Skip to content

Commit b27ead8

Browse files
committed
feat(builders): support coercion from Builder and Deferred instances
1 parent 176e3a7 commit b27ead8

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

koerce/builders.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ def __rxor__(self, other: Any) -> Deferred:
152152

153153
@cython.cclass
154154
class Builder:
155-
# TODO(kszucs): cover with tests
156155
@staticmethod
157156
def __coerce__(value):
158157
if isinstance(value, Builder):

koerce/tests/test_builders.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
Item,
1919
Just,
2020
Map,
21+
Builder,
2122
Seq,
2223
Unop,
2324
Var,
@@ -510,3 +511,10 @@ def test_deferred_is_not_truthy(obj):
510511
TypeError, match="The truth value of Deferred objects is not defined"
511512
):
512513
bool(obj)
514+
515+
516+
def test_builder_coercion():
517+
assert Builder.__coerce__(Deferred(Var("a"))) == Var("a")
518+
assert Builder.__coerce__(Var("a")) == Var("a")
519+
with pytest.raises(ValueError):
520+
Builder.__coerce__(1)

0 commit comments

Comments
 (0)