Finistere / antidote

Dependency injection for Python
MIT License
90 stars 9 forks source link

Optional doesn't work with union None from 3.10 #38

Closed pauleveritt closed 2 years ago

pauleveritt commented 2 years ago

Python 3.10 allows writing this:

@inject
def optional_greeter(greeter: MissingGreeter | None = inject.me()) -> str:

...instead of:

@inject
def optional_greeter(greeter: Optional[MissingGreeter] = inject.me()) -> str:

However, this results in:

../src/antidote/core/_injection.py:110: in _build_injection_blueprint
    annotated = _build_from_annotations(arguments)
../src/antidote/core/_injection.py:138: in _build_from_annotations
    dependency = extract_annotated_arg_dependency(arg)
../src/antidote/core/_annotations.py:97: in extract_annotated_arg_dependency
    raise TypeError(f"Cannot use marker @inject.me with non class type hint: examples.injection_flavors.MissingGreeter | None
Finistere commented 2 years ago

Indeed, thanks for reporting! Releasing a fix.

Finistere commented 2 years ago

Fixed with the release 1.2.0.