You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The interaction between @dataclass, @noninjectable, and auto_bind=True seems to be broken. I would not expect the following to work, because foo shouldn't be injected due to the decorator,
Traceback (most recent call last):
File "examples\injector_test.py", line 116, in <module>
parent = injector.get(Parent)
File "[USER_DIR]\AppData\Local\pypoetry\Cache\virtualenvs\[VENV]\lib\site-packages\injector\__init__.py", line 963, in get
result = scope_instance.get(interface, binding.provider).get(self)
File "[USER_DIR]\AppData\Local\pypoetry\Cache\virtualenvs\[VENV]\lib\site-packages\injector\__init__.py", line 291, in get
return injector.create_object(self._cls)
File "[USER_DIR]\AppData\Local\pypoetry\Cache\virtualenvs\[VENV]\lib\site-packages\injector\__init__.py", line 990, in create_object
self.call_with_injection(cls.__init__, self_=instance, kwargs=additional_kwargs)
File "[USER_DIR]\AppData\Local\pypoetry\Cache\virtualenvs\[VENV]\lib\site-packages\injector\__init__.py", line 1032, in call_with_injection
reraise(e, CallError(self_, callable, args, dependencies, e, self._stack))
File "[USER_DIR]\AppData\Local\pypoetry\Cache\virtualenvs\[VENV]\lib\site-packages\injector\__init__.py", line 211, in reraise
raise exception.with_traceback(tb)
File "[USER_DIR]\AppData\Local\pypoetry\Cache\virtualenvs\[VENV]\lib\site-packages\injector\__init__.py", line 1030, in call_with_injection
return callable(*full_args, **dependencies)
injector.CallError: Call to Parent.__init__(persistence=<__main__.Persistence object at 0x0000023D47334940>) failed: __init__() missing 1 required positional argument: 'foo' (injection stack: [])
The text was updated successfully, but these errors were encountered:
@dataclass does its dynamic code generation and attaches, amongst other things, a new __init__(p:Persistence,foo:int) method onto Parent.
@noninjectable expects an initializer (!)function, checks for existing function.__noninjectables__ and assigns "foo" to that attribute. However it gets called on the whole Parent, so now Parent.__noninjectables__ is set.
@inject can work with either a class or an __init__. It finds a type Parent with an initializer and continues, everything good.
Somewhere along the way it gets decided that Parent is to be constructed using a ClassProvider (which makes sense) and subsequently the free injector.get_bindings function is invoked with Parent.__init__. That's when it tries to find a __noninjectables__ attribute on the initializer, which doesn't exist (as it is set on Parent itself).
So seems to me like @noinjectable is the culprit as it doesn't have the
The interaction between
@dataclass
,@noninjectable
, andauto_bind=True
seems to be broken. I would not expect the following to work, becausefoo
shouldn't be injected due to the decorator,but it actually runs and produces
The same implementation without
@dataclass
throws an exception, as expected
The text was updated successfully, but these errors were encountered: