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 tkomiya
Recipients tkomiya
Date 2021-07-31.17:19:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1627751984.55.0.589090528607.issue44799@roundup.psfhosted.org>
In-reply-to
Content
I found `typing.get_type_hints()` raises TypeError for a variable annotated by `dataclasses.InitVar` when lazy annotations evaluation-feature is enabled (a.k.a `__future__.annotations`).

```
$ cat test.py
from __future__ import annotations
from dataclasses import dataclass, InitVar
from typing import get_type_hints

@dataclass
class Foo:
    attr: InitVar[int]


get_type_hints(Foo)
```

```
$ python -V
Python 3.9.6
$ python test.py
Traceback (most recent call last):
  File "/Users/tkomiya/work/sphinx/test.py", line 10, in <module>
    get_type_hints(Foo)
  File "/Users/tkomiya/.pyenv/versions/3.9.6/lib/python3.9/typing.py", line 1424, in get_type_hints
    value = _eval_type(value, base_globals, localns)
  File "/Users/tkomiya/.pyenv/versions/3.9.6/lib/python3.9/typing.py", line 290, in _eval_type
    return t._evaluate(globalns, localns, recursive_guard)
  File "/Users/tkomiya/.pyenv/versions/3.9.6/lib/python3.9/typing.py", line 545, in _evaluate
    type_ =_type_check(
  File "/Users/tkomiya/.pyenv/versions/3.9.6/lib/python3.9/typing.py", line 164, in _type_check
    raise TypeError(f"{msg} Got {arg!r:.100}.")
TypeError: Forward references must evaluate to types. Got dataclasses.InitVar[int].
```

It goes well if lazy annotations evaluation is disabled.
History
Date User Action Args
2021-07-31 17:19:44tkomiyasetrecipients: + tkomiya
2021-07-31 17:19:44tkomiyasetmessageid: <1627751984.55.0.589090528607.issue44799@roundup.psfhosted.org>
2021-07-31 17:19:44tkomiyalinkissue44799 messages
2021-07-31 17:19:44tkomiyacreate