Skip to content

Incremental mode crashes on #type: ignore comment on module when it was previously imported #1904

Closed
@Michael0x2a

Description

@Michael0x2a

Suppose you have the following two files:

a.py

import b  # type: ignore

b.py

# This file can be empty or non-empty

If you delete .mypy_cache then run mypy -i b.py a.py twice, you obtain the following error the second time you run mypy:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/runpy.py", line 184, in _run_module_as_main
    "__main__", mod_spec)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/michaellee/Work/mypy/mypy/__main__.py", line 5, in <module>
    main(None)
  File "/Users/michaellee/Work/mypy/mypy/main.py", line 40, in main
    res = type_check_only(sources, bin_dir, options)
  File "/Users/michaellee/Work/mypy/mypy/main.py", line 81, in type_check_only
    options=options)
  File "/Users/michaellee/Work/mypy/mypy/build.py", line 178, in build
    dispatch(sources, manager)
  File "/Users/michaellee/Work/mypy/mypy/build.py", line 1339, in dispatch
    process_graph(graph, manager)
  File "/Users/michaellee/Work/mypy/mypy/build.py", line 1480, in process_graph
    process_fresh_scc(graph, scc)
  File "/Users/michaellee/Work/mypy/mypy/build.py", line 1539, in process_fresh_scc
    graph[id].fix_cross_refs()
  File "/Users/michaellee/Work/mypy/mypy/build.py", line 1202, in fix_cross_refs
    fixup_module_pass_one(self.tree, self.manager.modules)
  File "/Users/michaellee/Work/mypy/mypy/fixup.py", line 17, in fixup_module_pass_one
    node_fixer.visit_symbol_table(tree.names)
  File "/Users/michaellee/Work/mypy/mypy/fixup.py", line 75, in visit_symbol_table
    stnode = lookup_qualified_stnode(self.modules, cross_ref)
  File "/Users/michaellee/Work/mypy/mypy/fixup.py", line 237, in lookup_qualified_stnode
    assert '.' in head, "Cannot find %s" % (name,)
AssertionError: Cannot find b

However, just running mypy -i a.py twice or swapping the order of the files and running mypy -a a.py b.py appears to both work fine -- it appears that incremental mode does not behave correctly when it first parses a module normally then encounters it a second time when it's annotated with # type: ignore.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions