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 tefra
Recipients tefra
Date 2021-03-28.09:52:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1616925169.4.0.788953716536.issue43646@roundup.psfhosted.org>
In-reply-to
Content
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+
History
Date User Action Args
2021-03-28 09:52:49tefrasetrecipients: + tefra
2021-03-28 09:52:49tefrasetmessageid: <1616925169.4.0.788953716536.issue43646@roundup.psfhosted.org>
2021-03-28 09:52:49tefralinkissue43646 messages
2021-03-28 09:52:49tefracreate