Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"AssertionError: Cannot find component" for local namedtuple #11121

Closed
ghost opened this issue Sep 16, 2021 · 0 comments · Fixed by #12804
Closed

"AssertionError: Cannot find component" for local namedtuple #11121

ghost opened this issue Sep 16, 2021 · 0 comments · Fixed by #12804

Comments

@ghost
Copy link

ghost commented Sep 16, 2021

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-defined error
  • 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 replacing from a import A by from a import crash (or any other valid name)
  • Definition of class InheritFromTuple in a.py
  • Argument fields in definition of namedtuple, e.g. by TupleType = 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants