Skip to content

Commit 1a418d3

Browse files
committed
Fixes up condition logic to be future proof for python 3.13
We were using a classproperty, which is not going to be allowed. We switch over to just using a class attribute. Also fixes up type hints for conditions -- these were incorrect
1 parent e22e10d commit 1a418d3

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

burr/core/action.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ class Condition(Function):
188188

189189
def __init__(self, keys: List[str], resolver: Callable[[State], bool], name: str = None):
190190
"""Base condition class. Chooses keys to read from the state and a resolver function.
191+
If you want a condition that defaults to true, use Condition.default or just default.
191192
192193
Note that you can use a few fundamental operators to build more complex conditions:
193194
@@ -278,16 +279,6 @@ def condition_func(state: State) -> bool:
278279
def __repr__(self):
279280
return f"condition: {self._name}"
280281

281-
@classmethod
282-
@property
283-
def default(self) -> "Condition":
284-
"""Returns a default condition that always resolves to True.
285-
You can also refer to this as ``from burr.core import default`` in the API.
286-
287-
:return: A default condition that always resolves to True
288-
"""
289-
return Condition([], lambda _: True, name="default")
290-
291282
@property
292283
def name(self) -> str:
293284
return self._name
@@ -344,13 +335,11 @@ def __invert__(self):
344335
return Condition(self._keys, lambda state: not self._resolver(state), name=f"~{self._name}")
345336

346337

347-
# Annotated inline as linters don't understand classmethods + properties
348-
# These, however, are allowed up until python 3.13
349-
# We're only keeping them as methods for documentation
350-
# TODO -- remove the static methods and make them
351-
default: Condition = Condition.default
352-
when: Condition = Condition.when
353-
expr: Condition = Condition.expr
338+
Condition.default = Condition([], lambda _: True, name="default")
339+
340+
default = Condition.default
341+
when = Condition.when
342+
expr = Condition.expr
354343

355344

356345
class Result(Action):
@@ -661,7 +650,6 @@ def is_async(self) -> bool:
661650
return True
662651

663652

664-
# TODO -- documentation for this
665653
class StreamingResultContainer(Iterator[dict]):
666654
"""Container for a streaming result. This allows you to:
667655

0 commit comments

Comments
 (0)