-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Description
Crash Report
mypy crashes when inheriting from a locally defined namedtuple, when all of the following is true:
- Its fields are not a literal
- Another file generates an
attr-definederror - Cache is enabled (without
--no-incremental)
Seems to be related to #10913, but produces a traceback similar to the closed #7281.
Traceback
Traceback (most recent call last):
File "/home/.../env/bin/mypy", line 8, in <module>
sys.exit(console_entry())
File "/home/.../env/lib/python3.7/site-packages/mypy/__main__.py", line 11, in console_entry
main(None, sys.stdout, sys.stderr)
File "mypy/main.py", line 87, in main
File "mypy/main.py", line 165, in run_build
File "mypy/build.py", line 179, in build
File "mypy/build.py", line 254, in _build
File "mypy/build.py", line 2697, in dispatch
File "mypy/build.py", line 3014, in process_graph
File "mypy/build.py", line 3092, in process_fresh_modules
File "mypy/build.py", line 1991, in fix_cross_refs
File "mypy/fixup.py", line 26, in fixup_module
File "mypy/fixup.py", line 90, in visit_symbol_table
File "mypy/fixup.py", line 49, in visit_type_info
File "mypy/types.py", line 846, in accept
File "mypy/fixup.py", line 154, in visit_instance
File "mypy/fixup.py", line 269, in lookup_qualified_typeinfo
File "mypy/fixup.py", line 297, in lookup_qualified
File "mypy/fixup.py", line 306, in lookup_qualified_stnode
File "mypy/lookup.py", line 47, in lookup_fully_qualified
AssertionError: Cannot find component 'TupleType@4' for 'a.TupleType@4'
To Reproduce
Use this script to reproduce:
#!/bin/sh
mkdir -p mypy_crash
cat >mypy_crash/a.py <<EOF
from collections import namedtuple
def crash(fields):
TupleType = namedtuple("TupleType", fields)
class InheritFromTuple(TupleType):
pass
EOF
cat >mypy_crash/b.py <<EOF
from a import A
EOF
rm -rf .mypy_cache
echo "First run, should be ok"
mypy mypy_crash/
echo
echo "Second run, with cache disabled, should be ok"
mypy --no-incremental mypy_crash/
echo
echo "Third run, with cache enabled, this should crash"
mypy mypy_crash/mypy does not crash if any of the following are removed:
- File
b.py - Import error in file
b.py, e.g. by replacingfrom a import Abyfrom a import crash(or any other valid name) - Definition of
class InheritFromTupleina.py - Argument
fieldsin definition of namedtuple, e.g. byTupleType = namedtuple("TupleType", 'a b c')
Your Environment
- Mypy version used: 0.910
- Mypy command-line flags: (none, see script)
- Mypy configuration options from
mypy.ini(and other config files): (none, can reproduce without mypy.ini) - Python version used: 3.7.9
- Operating system and version: Ubuntu 18.04.6 LTS (bionic)