-
-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comply with PEP-593 and support typing.Annotated #108
Comments
[REJECTED] Proposal A: Keep things the way they areThe way Use with Python versions < 3.9 remains the same: @autowired
def foo(service: Autowired(Service)): ... Using it with @autowired
def foo(service: Annotated[Autowired(Service), ...]): ... Pros
Cons
ConclusionI'm rejecting this approach since there seems to be no real benefits going on here and lots of problems. |
[ACCEPTED] Proposal B: Make
|
[REJECTED] Proposal C: Move
|
[REJECTED] Proposal D: denote autowired arguments in the
|
PEP-593 defines the a standard for annotation metadata other than type hinting through the use of
typing.Annotated
. This framework should comply with this recommendation and give full support totyping.Annotated
.This was originally brought to attention by @Euraxluo in #107 (comment)
Initial Considerations
Currently
Autowired(T)
already works well with most type checkers and linters since it evaluates toT
but this is not in line with the recommendation from PEP-593 to leave annotations primary to type hinting and other metadata to extras.We should decide how best to incorporate these changes in Injectable. I intend to lay down some possible paths we can go from here in this issue thread so anyone can share their thoughts if any and then eventually I'll commit to an implementation.
While
typing.Annotated
was introduced in Python 3.9, this frameworks currently supports all Python versions since 3.6. So we should think in a way that will deliver the best possible experience for all possible users and use cases of Injectable.Current State
When Python version < 3.9 then this is the only possible way to use Injectable:
When typing.Annotated is available (Python version >= 3.9), then this is also possible:
Therefore, since Python 3.9 one can probably use other libs which rely on annotations and fully support PEP-593 without undesired interactions or further problems with the use of Injectable.
Proposals
[rejected] Proposal A: Keep things the way they areAutowired
an alias oftyping.Annotated
[rejected] Proposal C: MoveAutowired
from the annotations to the default values of arguments[rejected] Proposal D: denote autowired arguments in the@autowired
decorator, dispensing the use ofAutowired
The text was updated successfully, but these errors were encountered: