Message411667
When PEP 585 was discussed and implemented we did not expect people to care as much about runtime types as they did.
I already explained that making list['Node'] incorporate a ForwardRef instance is unrealistic (we'd have to reimplement ForwardRef in C first).
It might be possible to change get_type_hints() to recognize strings, and deprecate ForwardRef altogether. But I suspect that that would break something else, since ForwardRef is documented (I had intended it to remain an internal detail but somehow it got exposed, I don't recall why).
Please stop asking why the decision was made (it sounds rather passive-aggressive to me) and start explaining the problem you are having in a way that we can actually start thinking about a solution.
I have boiled down the original example to a slightly simpler one (dataclasses are a red herring):
>>> from typing import get_type_hints, List
>>> class N:
... c1: list["N"]
... c2: List["N"]
...
>>> N.__annotations__
{'c1': list['N'], 'c2': typing.List[ForwardRef('N')]}
>>> get_type_hints(N)
{'c1': list['N'], 'c2': typing.List[__main__.N]}
The key problem here is that the annotation list['N'] is not expanded to list[N]. What can we do to make get_type_hint() produce list[N] instead here? |
|
Date |
User |
Action |
Args |
2022-01-25 19:23:09 | gvanrossum | set | recipients:
+ gvanrossum, eric.smith, lukasz.langa, levkivskyi, JelleZijlstra, miss-islington, n_rosenstein, BTaskaya, joperez, kj |
2022-01-25 19:23:09 | gvanrossum | set | messageid: <1643138589.41.0.269638550694.issue41370@roundup.psfhosted.org> |
2022-01-25 19:23:09 | gvanrossum | link | issue41370 messages |
2022-01-25 19:23:09 | gvanrossum | create | |
|