This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author GBeauregard
Recipients GBeauregard, JelleZijlstra, eric.smith
Date 2022-01-25.09:02:48
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1643101368.65.0.575407689959.issue46511@roundup.psfhosted.org>
In-reply-to
Content
In https://bugs.python.org/issue46491 the typing runtime behavior was changed so that `Annotated[Classvar[...]]` is now valid at runtime in order to alleviate tension between typing and non-typing annotation space uses. dataclasses.py should likely follow suit in its runtime use of `ClassVar` and `InitVar`.

Reviewing the code I see two areas that would need addressed:

1) `InitVar` needs changed so `Annotated[InitVar[...]]` is no longer a runtime error. This is currently a runtime error completely by accident: typing.py expects special type forms to be `callable()`, usually by implementing a `__call__` that throws an error, but `InitVar` does not implement this. Adding an  implementation like in typing.py would fix the runtime error:
https://github.com/python/cpython/blob/b1a3446f077b7d56b89f55d98dadb8018986a3e5/Lib/typing.py#L391-L392

2) The dataclasses-specific typehint introspection implementation needs modified to accommodate being wrapped by an `Annotated` annotation. I see in the comments the code is performance sensitive so I'm not sure what you want to do; f.ex. the regex needs modified, but it's not clean.

What are your thoughts?
History
Date User Action Args
2022-01-25 09:02:48GBeauregardsetrecipients: + GBeauregard, eric.smith, JelleZijlstra
2022-01-25 09:02:48GBeauregardsetmessageid: <1643101368.65.0.575407689959.issue46511@roundup.psfhosted.org>
2022-01-25 09:02:48GBeauregardlinkissue46511 messages
2022-01-25 09:02:48GBeauregardcreate