Skip to content

“AssertionError: Cannot find component” for local NamedTuple inside class method #10913

Closed
@andersk

Description

@andersk

Crash Report

This is a variant of #7281 that still crashes incremental checking on 0.910 and master (9f409c3), both of which include #10432, which was supposed to fix #7281.

The difference in this case is that the local NamedTuple is defined inside a class method rather than a global function.

To Reproduce

#!/bin/sh -eux

rm -rf .mypy_cache

echo 'from typing import NamedTuple' >breaking.py
echo 'class C:' >>breaking.py
echo '  def test(self):' >>breaking.py
echo '    class NT(NamedTuple):' >>breaking.py
echo '      pass' >>breaking.py

echo 'import breaking' >script.py
mypy script.py

echo '' >script.py
mypy script.py

echo 'import breaking' >script.py
mypy script.py

Traceback

Traceback (most recent call last):
  File "/home/anders/python/mypy/.direnv/python-3.9.5/bin/mypy", line 33, in <module>
    sys.exit(load_entry_point('mypy', 'console_scripts', 'mypy')())
  File "/home/anders/python/mypy/mypy/__main__.py", line 11, in console_entry
    main(None, sys.stdout, sys.stderr)
  File "/home/anders/python/mypy/mypy/main.py", line 87, in main
    res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
  File "/home/anders/python/mypy/mypy/main.py", line 165, in run_build
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "/home/anders/python/mypy/mypy/build.py", line 179, in build
    result = _build(
  File "/home/anders/python/mypy/mypy/build.py", line 254, in _build
    graph = dispatch(sources, manager, stdout)
  File "/home/anders/python/mypy/mypy/build.py", line 2698, in dispatch
    process_graph(graph, manager)
  File "/home/anders/python/mypy/mypy/build.py", line 3015, in process_graph
    process_fresh_modules(graph, prev_scc, manager)
  File "/home/anders/python/mypy/mypy/build.py", line 3093, in process_fresh_modules
    graph[id].fix_cross_refs()
  File "/home/anders/python/mypy/mypy/build.py", line 1992, in fix_cross_refs
    fixup_module(self.tree, self.manager.modules,
  File "/home/anders/python/mypy/mypy/fixup.py", line 26, in fixup_module
    node_fixer.visit_symbol_table(tree.names, tree.fullname)
  File "/home/anders/python/mypy/mypy/fixup.py", line 77, in visit_symbol_table
    stnode = lookup_qualified_stnode(self.modules, cross_ref,
  File "/home/anders/python/mypy/mypy/fixup.py", line 306, in lookup_qualified_stnode
    return lookup_fully_qualified(name, modules, raise_on_missing=not allow_missing)
  File "/home/anders/python/mypy/mypy/lookup.py", line 47, in lookup_fully_qualified
    assert key in names, "Cannot find component %r for %r" % (key, name)
AssertionError: Cannot find component 'NT@4' for 'breaking.C.NT@4'

Your Environment

  • Mypy version used: 0.910, 0.920+dev.9f409c3d89c7fa65eff8cf67883473487e6effd4
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.9.5
  • Operating system and version: NixOS 21.11

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions