python / python/mypy

mypy crashes on a dataclass

Open
#20,476 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

crash topic-dataclasses
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Crash Report

Traceback

Traceback (most recent call last):
  File "/home/dnpetrov/Work/memory_tests/venv/bin/mypy", line 8, in <module>
    sys.exit(console_entry())
             ^^^^^^^^^^^^^^^
  File "/home/dnpetrov/Work/memory_tests/venv/lib/python3.12/site-packages/mypy/__main__.py", line 15, in console_entry
    main()
  File "mypy/main.py", line 103, in main
  File "mypy/main.py", line 187, in run_build
  File "mypy/build.py", line 193, in build
  File "mypy/build.py", line 268, in _build
  File "mypy/build.py", line 2950, in dispatch
  File "mypy/build.py", line 3348, in process_graph
  File "mypy/build.py", line 3443, in process_stale_scc
  File "mypy/semanal_main.py", line 99, in semantic_analysis_for_scc
  File "mypy/semanal_main.py", line 432, in apply_class_plugin_hooks
AssertionError: Internal error: too many class plugin hook passes

To Reproduce

Following code crashes mypy:

from dataclasses import dataclass

def fn(a: int) -> int:
    return a

@dataclass
class Test:
    foo = fn
    foo: int = 42

While the code itself, indeed, looks very strange, mypy should not crash, or at least should provide some meaningful diagnostic instead of "Internal error: too many class plugin hook passes".

Your Environment

$ mypy --version
mypy 1.11.2 (compiled: yes)
$ python --version
Python 3.12.3

Also reproduces on the latest and greatest master branch (30b2a2d99a05c5176eff449b80abb61eae5f2043).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the crash with the dataclass example, then inspect mypy/semanal_main.py at apply_class_plugin_hooks and the related processing in mypy/build.py. Trace why the class plugin hook pass limit is reached; done means this input no longer crashes and instead produces a meaningful diagnostic or completes successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.