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

Crash on namedtuple + @dataclass #18527

Open
ericbuehl opened this issue Jan 24, 2025 · 2 comments
Open

Crash on namedtuple + @dataclass #18527

ericbuehl opened this issue Jan 24, 2025 · 2 comments

Comments

@ericbuehl
Copy link

Crash Report

running under python 3.13.1 results in the following crash when it does not crash under 3.12.8

Traceback

Traceback (most recent call last):
  File "<redacted>/.venv/bin/mypy", line 8, in <module>
    sys.exit(console_entry())
             ~~~~~~~~~~~~~^^
  File "<redacted>/.venv/lib/python3.13/site-packages/mypy/__main__.py", line 15, in console_entry
    main()
    ~~~~^^
  File "mypy/main.py", line 109, in main
  File "mypy/main.py", line 193, in run_build
  File "mypy/build.py", line 194, in build
  File "mypy/build.py", line 269, in _build
  File "mypy/build.py", line 2940, in dispatch
  File "mypy/build.py", line 3338, in process_graph
  File "mypy/build.py", line 3433, in process_stale_scc
  File "mypy/semanal_main.py", line 99, in semantic_analysis_for_scc
  File "mypy/semanal_main.py", line 443, in apply_class_plugin_hooks
  File "mypy/semanal_main.py", line 479, in apply_hooks_to_class
  File "mypy/plugins/dataclasses.py", line 966, in dataclass_class_maker_callback
  File "mypy/plugins/dataclasses.py", line 389, in transform
  File "mypy/plugins/dataclasses.py", line 409, in _add_dunder_replace
  File "mypy/plugins/common.py", line 238, in add_method_to_class
  File "mypy/plugins/common.py", line 315, in _prepare_class_namespace
ValueError: list.remove(x): x not in list

To Reproduce

mypy <source dir>

Your Environment

This error occurs on a large proprietary code base. I have removed all custom configuration options and plugins normally specified in pyproject.toml, cleaned .mypy_cache dir and reproduced the error with a vanilla mypy invocation. No crash when using python 3.12.8, but traceback above occurs when switching to python 3.13.1

  • Mypy version used: 1.14.1
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: tested successfully under python 3.12.8, fails under 3.13.1
  • Operating system and version: OS X Sequoia
@ericbuehl ericbuehl changed the title Crash under Python 3.13: list.remove(x): x not in list Crash under Python 3.13: ValueError: list.remove(x): x not in list Jan 25, 2025
@cdce8p
Copy link
Collaborator

cdce8p commented Jan 25, 2025

Thanks for the report @ericbuehl! Are you able to narrow the crash down to a particular file, ideally an example you can post here? Without it, this would be quite difficult to resolve.

For what it's worth, I know at least one large project which is also already running on 3.13.1 and hasn't encountered the crash yet.

@ericbuehl
Copy link
Author

@cdce8p I was able to narrow the crash down to a concise repro:

from dataclasses import dataclass
from typing import NamedTuple

@dataclass
class Imageable(NamedTuple):
    id: int

I'm not sure of the practical need for this dataclass+namedtuple but alas mypy probably shouldn't crash nonetheless

@JelleZijlstra JelleZijlstra changed the title Crash under Python 3.13: ValueError: list.remove(x): x not in list Crash on namedtuple + @dataclass Jan 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants