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 kj
Recipients eric.smith, gvanrossum, kj, xirdneh
Date 2021-02-19.15:00:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1613746825.07.0.301963570271.issue43257@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2021-02-19 15:00:25kjsetrecipients: + kj, gvanrossum, eric.smith, xirdneh
2021-02-19 15:00:25kjsetmessageid: <1613746825.07.0.301963570271.issue43257@roundup.psfhosted.org>
2021-02-19 15:00:25kjlinkissue43257 messages
2021-02-19 15:00:24kjcreate