Message411404
Currently, `typing.Annotated` (PEP 593) cannot be used at runtime with `typing.Final` and `typing.ClassVar` with `Annotated` on the outside:
```
from typing import Annotated, Final
# TypeError: typing.Final[int] is not valid as type argument
var: Annotated[Final[int], "foo"] = 4
```
The only tenuously related mention of this I can find in a PEP is in PEP 593 (Annotated) which states "The first argument to Annotated must be a valid type".
I believe the runtime behavior should be changed to allow any ordering for `Annotated` with `ClassVar` and `Final`. This was discussed in the typing-sig PEP 655 thread (TypedDict `Required` and `NotRequired`) where the current plan is to allow `Required`/`NotRequired` in any nesting order with `Annotated` while suggesting the `ClassVar`/`Final` ordering restriction be lifted: https://mail.python.org/archives/list/typing-sig@python.org/message/22CJ5TJGIJ563D6ZKB7R3VUZXTZQND5X/
The argument for doing so is on the mailing list: https://mail.python.org/archives/list/typing-sig@python.org/message/MPMOIBX3XFXCD4ZNDC6AV4CLSI5LN544/
To summarize: adopting an overly strict view of what constitutes a valid type for `Annotated` creates difficulties for people who use runtime introspection of `Annotated` annotations by requiring them to parse additional typing or field annotations (https://bugs.python.org/msg411067). This needlessly exacerbates tension between typing and non-typing uses of annotation space. In order to be a good citizen to other annotation users, the `Annotated` runtime ordering restriction should be lifted. |
|
Date |
User |
Action |
Args |
2022-01-23 19:03:20 | GBeauregard | set | recipients:
+ GBeauregard |
2022-01-23 19:03:20 | GBeauregard | set | messageid: <1642964600.39.0.642396335875.issue46491@roundup.psfhosted.org> |
2022-01-23 19:03:20 | GBeauregard | link | issue46491 messages |
2022-01-23 19:03:20 | GBeauregard | create | |
|