Skip to content

issue with dataclass default properties (again) #16141

@ruro

Description

@ruro

The code described in #8025 still crashes in the same place in mypy 1.5.1 despite the fact that the issue was closed back in 2019 as fixed. Either it was never actually fixed or this is a regression.

To Reproduce

from dataclasses import dataclass, field


@dataclass
class Foo:
    @property
    def c(self) -> int:
        return 0

    c: int = field(init=False, default=c)

then run mypy foo.py.

Traceback

Traceback (most recent call last):
  File "/tmp/tmp.nVCcmNZCU9/.venv/bin/mypy", line 8, in <module>
    sys.exit(console_entry())
             ^^^^^^^^^^^^^^^
  File "/tmp/tmp.nVCcmNZCU9/.venv/lib/python3.11/site-packages/mypy/__main__.py", line 15, in console_entry
    main()
  File "mypy/main.py", line 94, in main
  File "mypy/main.py", line 173, in run_build
  File "mypy/build.py", line 195, in build
  File "mypy/build.py", line 268, in _build
  File "mypy/build.py", line 2927, in dispatch
  File "mypy/build.py", line 3325, in process_graph
  File "mypy/build.py", line 3420, in process_stale_scc
  File "mypy/semanal_main.py", line 99, in semantic_analysis_for_scc
  File "mypy/semanal_main.py", line 439, in apply_class_plugin_hooks
  File "mypy/semanal_main.py", line 475, in apply_hooks_to_class
  File "mypy/plugins/dataclasses.py", line 932, in dataclass_class_maker_callback
    # included, despite the fact that they're not real fields.  That's
  File "mypy/plugins/dataclasses.py", line 231, in transform
    repr_running = set()
  File "mypy/plugins/dataclasses.py", line 576, in collect_attributes
    # there's at least one keyword-only arg, there needs to be a test here
AssertionError

The source lines in the traceback are wrong for some reason, but if you actually go to lines indicated in the traceback, you can plainly see that they are (mostly) the same as in #8025.

Your Environment

  • Mypy version used: 1.3.0 (compiled: no), 1.5.1 (compiled: yes)
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.11.5
  • Operating system and version: Manjaro/Arch Linux

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions