Fix callseq deduplication error, allow using Some|None=None args with no commutativity error, add ignore_basictypes_return for a ConversionPoint.from_fn

This commit is contained in:
2025-10-17 00:51:29 +03:00
parent dbecef1977
commit 74d78b1957
6 changed files with 53 additions and 9 deletions

View File

@@ -47,6 +47,37 @@ def test_default_consumer_args():
assert dep == (123, '1')
def test_optional_default_none_consumer_args():
repo = ConvRepo()
@repo.mark_injector()
def b_to_a(b: B | None = None) -> A:
return A(int(b.b))
@repo.mark_injector()
def a_to_b(a: A) -> B | None:
return B(float(a.a))
@repo.mark_injector()
def int_to_a(i: int) -> A:
return A(i)
def consumer(dep: A, opt_dep: optC = '42') -> tuple[int, str]:
return dep.a, opt_dep
fn1 = repo.get_conversion((B,), consumer, force_commutative=True, force_async=False, allow_async=False)
dep = fn1(B(42.1))
assert dep == (42, '42')
fn2 = repo.get_conversion((int,), consumer, force_commutative=True, force_async=False, allow_async=False)
dep = fn2(123)
assert dep == (123, '42')
fn3 = repo.get_conversion((int, optC), consumer, force_commutative=True, force_async=False, allow_async=False)
dep = fn3(123, '1')
assert dep == (123, '1')
def test_default_inj_args():
repo = ConvRepo()
@@ -79,7 +110,6 @@ def test_default_inj_args():
def test_default_graph_override():
repo = ConvRepo()
@repo.mark_injector()
@@ -111,4 +141,4 @@ def test_default_graph_override():
fn3 = repo.get_conversion((int, optC,), consumer, force_commutative=True, force_async=False, allow_async=False)
dep = fn3(123, '0')
assert dep == 123
assert dep == 123

View File

@@ -17,7 +17,7 @@ type optC = str
def test_default_consumer_args():
repo = ConvRepo()
repo = ConvRepo(store_sources=True)
@repo.mark_injector()
def b_to_a(b: B) -> A:
@@ -106,3 +106,13 @@ def test_pipeline_with_subgraph_duplicates():
assert b_to_a_calls[0] == 1
assert cons1_calls[0] == 5
assert cons2_calls[0] == 4
def convertor(_5891515089754: "<class 'test_pipeline.B'>"):
# <function test_default_consumer_args.<locals>.b_to_a at 0x7f5bb1be02c0>
_5891515089643 = _conv_funcmap[8751987548204](b=_5891515089754)
# <function test_default_consumer_args.<locals>.consumer1 at 0x7f5bb1be0c20>
_8751987542640 = _conv_funcmap[8751987548354](dep=_5891515089643)
# <function test_default_consumer_args.<locals>.consumer2 at 0x7f5bb1be0540>
_8751987537115 = _conv_funcmap[8751987548244](dep=_5891515089643, dep1=_8751987542640)
return _8751987542640