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

issue with dataclass default properties (again) #16141

Closed
RuRo opened this issue Sep 18, 2023 · 3 comments
Closed

issue with dataclass default properties (again) #16141

RuRo opened this issue Sep 18, 2023 · 3 comments

Comments

@RuRo
Copy link

RuRo commented Sep 18, 2023

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

Thanks for re-reporting!

(Looks like #8025 got closed as a duplicate of #6493. The crash in #6493 was fixed in 0.720, but I guess this one never was. 2019 is long ago enough that bisecting to figure out the relevant change would be annoying)

@sobolevn
Copy link
Member

sobolevn commented Sep 19, 2023

@hauntsaninja this is a different issue. The problem here is that c.node is not expected to be Decorator.

I think the easiest way right now would be just to raise an error and continue. At least, it won't crash.

sobolevn added a commit that referenced this issue Sep 19, 2023
@AlexWaygood
Copy link
Member

Fixed in #16147

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