Description
mypy generally crashes with an internal error if it winds up trying to handle a file named typing.py
, apparently due to confusion with the built-in typing
module. Here's the simplest test case I've found (tested on 0.4.3 and master):
(mypyve) vm:/tmp/test1$ cat typing.py
from collections import namedtuple
x = namedtuple('x', [])
(mypyve) vm:/tmp/test1$ mypy -s typing.py
Traceback (most recent call last):
File "/tmp/mypyve/bin/mypy", line 6, in <module>
main(__file__)
File "/tmp/mypyve/lib/python3.4/site-packages/mypy/main.py", line 40, in main
res = type_check_only(sources, bin_dir, options)
File "/tmp/mypyve/lib/python3.4/site-packages/mypy/main.py", line 81, in type_check_only
options=options)
File "/tmp/mypyve/lib/python3.4/site-packages/mypy/build.py", line 177, in build
dispatch(sources, manager)
File "/tmp/mypyve/lib/python3.4/site-packages/mypy/build.py", line 1338, in dispatch
process_graph(graph, manager)
File "/tmp/mypyve/lib/python3.4/site-packages/mypy/build.py", line 1481, in process_graph
process_stale_scc(graph, scc)
File "/tmp/mypyve/lib/python3.4/site-packages/mypy/build.py", line 1554, in process_stale_scc
graph[id].semantic_analysis()
File "/tmp/mypyve/lib/python3.4/site-packages/mypy/build.py", line 1303, in semantic_analysis
self.manager.semantic_analyzer.visit_file(self.tree, self.xpath)
File "/tmp/mypyve/lib/python3.4/site-packages/mypy/semanal.py", line 243, in visit_file
self.accept(d)
File "/tmp/mypyve/lib/python3.4/site-packages/mypy/semanal.py", line 2307, in accept
node.accept(self)
File "/tmp/mypyve/lib/python3.4/site-packages/mypy/nodes.py", line 761, in accept
return visitor.visit_assignment_stmt(self)
File "/tmp/mypyve/lib/python3.4/site-packages/mypy/semanal.py", line 1076, in visit_assignment_stmt
self.process_namedtuple_definition(s)
File "/tmp/mypyve/lib/python3.4/site-packages/mypy/semanal.py", line 1416, in process_namedtuple_definition
named_tuple = self.check_namedtuple(s.rvalue, name)
File "/tmp/mypyve/lib/python3.4/site-packages/mypy/semanal.py", line 1454, in check_namedtuple
info = self.build_namedtuple_typeinfo(name, items, types)
File "/tmp/mypyve/lib/python3.4/site-packages/mypy/semanal.py", line 1543, in build_namedtuple_typeinfo
info.mro = [info] + info.tuple_type.fallback.type.mro
TypeError: can only concatenate list (not "NoneType") to list
*** INTERNAL ERROR ***
typing.py:3: error: Internal error -- please report a bug at https://github.com/python/mypy/issues
NOTE: you can use "mypy --pdb ..." to drop into the debugger when this happens.
This is the same error message reported in a comment in #1293. The root cause is that mypy ships a file called typing.py in site-packages, so if site-packages winds up on the path (even implicitly, even with -s), it dies:
(mypyve) vm:/tmp/mypyve/lib/python3.4/site-packages$ mypy -s typing.py
Traceback (most recent call last):
...
(mypyve) vm:/tmp/mypyve/lib/python3.4/site-packages$ touch hello.py
(mypyve) vm:/tmp/mypyve/lib/python3.4/site-packages$ mypy -s hello.py
Traceback (most recent call last):
...
This makes it impossible to analyze a package along with even a subset of its dependencies as the implicit addition to MYPYPATH results in an internal error.