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 AlexWaygood, GBeauregard, JelleZijlstra, eric.smith, gvanrossum, kj, sobolevn
Date 2022-01-28.00:03:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1643328223.01.0.194402983458.issue46553@roundup.psfhosted.org>
In-reply-to
Content
It's acceptable to mypy, and pyright added support a few months ago when I made an issue and Eric Traut discovered this pattern in the wild too.

Some of the other type checkers (pyre) still error I believe. My feeling is that since this has apparently become used in practice we should fix the runtime error for when it's stringified, but we don't necessarily need to prescribe that it's a legal type annotation for type checkers (?). If I was prescribing how to use ClassVar in a vacuum, I don't see any good typing reason we should prohibit this.

re: moving dataclasses: I'm not sure either! I'm trying to look into the issues it brings up in practice to weigh against the difficulties of maintaining the existing bespoke introspection implementation and the problems it has (dealing with stringified annotations, supporting renaming the Annotated symbol).

I made an implementation that fully moves dataclasses over to using `get_type_hints` (and got all the tests to pass), but my feeling right now is that a few issues are too serious for it to be viable:

1) the namespaces are a mess, and issues like https://github.com/python/typing/issues/508 don't have a solution at the moment
2) get_type_hints paints a wide brush on the entire class when it raises for errors, so it's not very viable to deal with non-typing non-Annotated[] annotations as a one-off

There's also nontechnical issues, like the potential politics of making dataclasses always import typing. I'll be updating bpo-46511 later with thoughts.
History
Date User Action Args
2022-01-28 00:03:43GBeauregardsetrecipients: + GBeauregard, gvanrossum, eric.smith, JelleZijlstra, sobolevn, kj, AlexWaygood
2022-01-28 00:03:43GBeauregardsetmessageid: <1643328223.01.0.194402983458.issue46553@roundup.psfhosted.org>
2022-01-28 00:03:43GBeauregardlinkissue46553 messages
2022-01-28 00:03:42GBeauregardcreate