Ken Jin <[email protected]> added the comment:
Hmm I noticed this occurs in Python 3.9 but not 3.10. If you insert ``from
__future__ import annotations`` at the start of your code, it stops erroring.
Anyways, I don't think this is dataclass specific, the following code using a
plain class also errors:
```
from typing import get_type_hints
class T:
str: str = 'a'
get_type_hints(T) # Error.
```
Inspecting __annotations__ tells us why:
>>> T.__annotations__
{'str': 'a'}
You can see that the annotations are wrong. Meanwhile with from __future__
import annotations:
>>> T.__annotations__
{'str': 'str'}
Seeing that SETUP_ANNOTATIONS in ceval.c didn't change, I suspect it's compiler
related.
----------
nosy: +gvanrossum, kj
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue43257>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com