Get rid of manual consumer fn unwrapping for callgraph generation
This commit is contained in:
@@ -38,3 +38,33 @@ def test_basic():
|
||||
fn2 = repo.get_conversion((int,), consumer, force_commutative=True, force_async=False, allow_async=False)
|
||||
dep = fn2(123)
|
||||
assert dep == 123
|
||||
|
||||
|
||||
def test_union_deps():
|
||||
repo = ConvRepo()
|
||||
|
||||
@repo.mark_injector()
|
||||
def b_to_a(b: B) -> A:
|
||||
return A(int(b.b))
|
||||
|
||||
@repo.mark_injector()
|
||||
def a_to_b(a: A) -> B:
|
||||
return B(float(a.a))
|
||||
|
||||
@repo.mark_injector()
|
||||
def int_to_a(i: int) -> A:
|
||||
return A(i)
|
||||
|
||||
def consumer(dep: A | B) -> int:
|
||||
if isinstance(dep, A):
|
||||
return dep.a
|
||||
else:
|
||||
return int(dep.b)
|
||||
|
||||
fn1 = repo.get_conversion((B,), consumer, force_commutative=True, force_async=False, allow_async=False)
|
||||
dep = fn1(B(42.1))
|
||||
assert dep == 42
|
||||
|
||||
fn2 = repo.get_conversion((int,), consumer, force_commutative=True, force_async=False, allow_async=False)
|
||||
dep = fn2(123)
|
||||
assert dep == 123
|
||||
|
||||
Reference in New Issue
Block a user