python / mypy

Optional static typing for Python
https://www.mypy-lang.org/
Other
18.18k stars 2.77k forks source link

Daemon issues with retargeting re-exported names #6548

Open msullivan opened 5 years ago

msullivan commented 5 years ago

Consider the following test:

[case testRetargetReexport]
from m import M

def f(x: M) -> None: ...

f(M())

[file m.py]
from n import M
[file m.py.2]
from q import M

[file n.py]
class M: ...

[file q.py]
class M: ...
[out]
==

The daemon fails in step two with the error Argument 1 to "f" has incompatible type "q.M"; expected "n.M"

msullivan commented 5 years ago

There is a related seeming bug with NamedTuples whose names don't match their line numbers:

[case testRetargetReexportNamedTuple]
from m import M

def f(x: M) -> None: ...

f(M(0))

[file m.py]
from n import M

[file n.py]
from typing import NamedTuple
M = NamedTuple('_N', [('x', int)])

[file n.py.2]
# oh no
from typing import NamedTuple
M = NamedTuple('_N', [('x', int)])

[out]
==

Fails with Argument 1 to "f" has incompatible type "_N@3"; expected "_N@2"

Here it is also arguably a bug that the names get messed up like that, but it works if there is not a re-export...

ilevkivskyi commented 5 years ago

I think I was also hit by this recently. I raise the priority to high, since this is a relatively large area where daemon's behavior is problematic.