Skip to content

AssertionError: Should never get here in normal mode #14254

Closed

Description

@hamdanal

Crash Report

The first run of mypy reports an error normally. The second run crashes with AssertionError: Should never get here in normal mode. Clearing the cache with rm -rf .mypy_cache prevents the crash in the next run but keeps crashing in the runs after.

Full reproducer below.

Traceback

$ mypy --ignore-missing-imports t/
Traceback (most recent call last):
  File "/tmp/venv/bin/mypy", line 8, in <module>
    sys.exit(console_entry())
  File "/tmp/venv/lib/python3.10/site-packages/mypy/__main__.py", line 15, in console_entry
    main()
  File "/tmp/venv/lib/python3.10/site-packages/mypy/main.py", line 95, in main
    res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
  File "/tmp/venv/lib/python3.10/site-packages/mypy/main.py", line 174, in run_build
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "/tmp/venv/lib/python3.10/site-packages/mypy/build.py", line 194, in build
    result = _build(
  File "/tmp/venv/lib/python3.10/site-packages/mypy/build.py", line 277, in _build
    graph = dispatch(sources, manager, stdout)
  File "/tmp/venv/lib/python3.10/site-packages/mypy/build.py", line 2914, in dispatch
    process_graph(graph, manager)
  File "/tmp/venv/lib/python3.10/site-packages/mypy/build.py", line 3304, in process_graph
    process_fresh_modules(graph, prev_scc, manager)
  File "/tmp/venv/lib/python3.10/site-packages/mypy/build.py", line 3385, in process_fresh_modules
    graph[id].fix_cross_refs()
  File "/tmp/venv/lib/python3.10/site-packages/mypy/build.py", line 2120, in fix_cross_refs
    fixup_module(self.tree, self.manager.modules, self.options.use_fine_grained_cache)
  File "/tmp/venv/lib/python3.10/site-packages/mypy/fixup.py", line 53, in fixup_module
    node_fixer.visit_symbol_table(tree.names, tree.fullname)
  File "/tmp/venv/lib/python3.10/site-packages/mypy/fixup.py", line 125, in visit_symbol_table
    self.visit_type_info(value.node)
  File "/tmp/venv/lib/python3.10/site-packages/mypy/fixup.py", line 87, in visit_type_info
    info.declared_metaclass.accept(self.type_fixer)
  File "/tmp/venv/lib/python3.10/site-packages/mypy/types.py", line 1316, in accept
    return visitor.visit_instance(self)
  File "/tmp/venv/lib/python3.10/site-packages/mypy/fixup.py", line 198, in visit_instance
    inst.type = lookup_fully_qualified_typeinfo(
  File "/tmp/venv/lib/python3.10/site-packages/mypy/fixup.py", line 339, in lookup_fully_qualified_typeinfo
    assert (
AssertionError: Should never get here in normal mode, got Var:t.types.Meta instead of TypeInfo

To Reproduce

Create the following project structure:

$ tree t/
t/
├── file_with_any_type_error.py
├── __init__.py
└── types.py

0 directories, 3 files

$ cat t/__init__.py

$ cat t/types.py
from missing_module import Meta

class Foo(metaclass=Meta): ...

$ cat t/file_with_any_type_error.py
x: str
x = 1

Run mypy --ignore-missing-imports t/ more than one time without deleting the .mypy_cache folder.

Your Environment

  • Mypy version used: $ mypy 1.0.0+dev.734a0b96b79f20b3290ca5fee97c749ccb2e308f (compiled: no)
  • Mypy command-line flags: --ignore-missing-imports
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: Python 3.10.6 (main, Nov 2 2022, 18:53:38) [GCC 11.3.0]
  • Operating system and version:
    • OS: Ubuntu 22.04.1 LTS on Windows 10 x86_64
    • Kernel: 5.15.74.2-microsoft-standard-WSL2

Activity

  1. hauntsaninja commented on Dec 19, 2022

    @hauntsaninja
    Collaborator

    Thanks for the great issue report. Can still reproduce against latest master.

  2. added a commit that references this issue on Jan 22, 2023
    e8c844b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions