Gregory Beauregard <g...@greg.red> added the comment:

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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue46553>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to