python-injector / python-injector/injector
Unable to inject annotated types with inject attribute
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.5k
- Forks
- 94
- PR merge metrics
- No merged PRs in 30d
Description
I tried to inject annotated type into the class via the @inject decorator, and the injector injected the default value for the annotated source class. The injector always extracts the source class from the annotated and replaces the original attributed type with the extracted one in the bindings map. So when you use Annotated[str, "foo"] and try to @inject it into some class, the constructor will receive an empty string instead of the provider you set while configuring the binder.
I prepared the PR with the possible fix and the test describing the issue
PR 266
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing PR 266 and its accompanying test, which describe the annotated-type injection failure. Verify the behavior when injecting Annotated[str, "foo"] against a configured provider, and consider the issue done when the provider is used instead of the annotated source class's default value and the test passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100