Message389634
Consider two modules with the same name forward references with the same type construct
./a.py
```
from typing import Optional
class Root:
a: Optional["Person"]
class Person:
value: str
```
./b.py
```
from typing import Optional
class Root:
b: Optional["Person"]
class Person:
value: str
```
There is a naming conflict, I think due to caching, and the type hint of the second property points to the first one.
```
>>> from typing import get_type_hints, Optional
>>> from a import Root as RootA, Person as PersonA
>>> from b import Root as RootB, Person as PersonB
>>>
>>> roota_hints = get_type_hints(RootA)
>>> rootb_hints = get_type_hints(RootB)
>>>
>>> print(roota_hints)
{'a': typing.Optional[a.Person]}
>>> print(rootb_hints)
{'b': typing.Optional[a.Person]}
>>>
>>> assert roota_hints["a"] == Optional[PersonA]
>>> assert rootb_hints["b"] == Optional[PersonB] # fails, points to PersonA
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AssertionError
>", line 1, in <module>
AssertionError
>>>
```
The behavior started in python 3.10, I am not sure which alpha version, I am using 3.10.0a6+ |
|
Date |
User |
Action |
Args |
2021-03-28 09:52:49 | tefra | set | recipients:
+ tefra |
2021-03-28 09:52:49 | tefra | set | messageid: <1616925169.4.0.788953716536.issue43646@roundup.psfhosted.org> |
2021-03-28 09:52:49 | tefra | link | issue43646 messages |
2021-03-28 09:52:49 | tefra | create | |
|