UnboundLocalError when reusing dependencies
sscherfke opened this issue · comments
Incant fails when the invoked function uses a dependency, that is already used by another dependency:
import incant
incanter = incant.Incanter()
@incanter.register_by_name
def x() -> int:
return 1
@incanter.register_by_name
def y(x: int) -> int:
return x + 1
def func(x: int, y: int) -> None:
assert x + 1 == y
incanter.invoke(func)
Traceback (most recent call last):
File "/home/stefan/.../lib/tasks.py", line 28, in <module>
incanter.invoke(func)
File "/home/stefan/emsconda/lib/python3.10/site-packages/incant/__init__.py", line 112, in invoke
return self.prepare(fn, is_async=False)(*args, **kwargs)
File "<incant generated invoke of func>", line 2, in invoke_func
UnboundLocalError: local variable '_incant_local_1' referenced before assignment
It does not matter whether I use register_by_name
or register_by_type
.
Python is 3.10, incant is 22.1.0.
Interesting, will take a look!
This should be fixed on main
. I plan on doing a little more polish and releasing in the next few days. Mind retesting against main
until then?
I've added your case to the test suite.
Thanks for the quick fix :)
One more question: Will x()
only be called once and the same result used for both, y()
and func()
? Like with pytest fixtures?
Only once! The same result (the same local variable, in fact) will be passed to all dependents.
Fix released