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: Should never get here in normal mode #14254

Closed
hamdanal opened this issue Dec 4, 2022 · 1 comment · Fixed by #14495
Closed

AssertionError: Should never get here in normal mode #14254

hamdanal opened this issue Dec 4, 2022 · 1 comment · Fixed by #14495

Comments

@hamdanal
Copy link
Collaborator

hamdanal commented Dec 4, 2022

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
@hauntsaninja
Copy link
Collaborator

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

@hauntsaninja hauntsaninja mentioned this issue Dec 19, 2022
17 tasks
JukkaL pushed a commit that referenced this issue Jan 22, 2023
Fixes #14254

This essentially re-implements #13605
in a simpler way that also works in incremental mode. Also I decided to
set `meta_fallback_to_any` in case of errors, to match how we do this
for base classes.
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.

3 participants