Description
This is a rather weird bug that showed up for us in production when I tried to upgrade to 0.600. The repro requires at least four files, so I decided to put it in its own little repo: https://github.com/JelleZijlstra/tmp-mypy-bug. Running mypy baddir
(with mypy 0.600) reproes the bug there.
Basically, the test case has four files that import each other (__init__
-> ba
-> b
-> c
). ba
additionally uses a name from b
(defines as LOCAL_HOSTNAME = socket.gethostname()
), and the usage of this name causes a "Cannot determine type" error. Various minor transformations (making LOCAL_HOSTNAME
a string literal; removing c.py
) make the error go away.
Interestingly, renaming ba.py
to a.py
(as in the gooddir
in the repo) silences the bug. This suggests that this is somehow related to the alphabetical order of the files involved. The bug didn't appear in 0.590. I'm guessing it's somehow related to the various FileSystemCache changes that went into 0.600. https://github.com/python/mypy/blob/master/mypy/find_sources.py#L78 is suspicious in that it does a sort and was new in 0.600, although really I'm just guessing.