[New-bugs-announce] [issue46553] typing: get_type_hints on stringified lone ClassVar raises TypeError

Gregory Beauregard report at bugs.python.org
Thu Jan 27 15:50:13 EST 2022


New submission from Gregory Beauregard <greg at greg.red>:

```
class C:
    a: "ClassVar"

get_type_hints(C, globals())  # TypeError: Plain typing.ClassVar is not valid as type argument
```

A stringified lone ClassVar raises at runtime, but this pattern is tested for in dataclasses unit tests and used in the wild. The PEP is not clear that it should or should not be used with arguments, and it works fine when not stringified.

The fix for this is trivial and I can submit a patch if there's agreement.

----------
components: Library (Lib)
messages: 411923
nosy: GBeauregard, Jelle Zijlstra, eric.smith, gvanrossum, kj
priority: normal
severity: normal
status: open
title: typing: get_type_hints on stringified lone ClassVar raises TypeError
versions: Python 3.10, Python 3.11, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46553>
_______________________________________


More information about the New-bugs-announce mailing list