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

__match_args__ is not added to dataclasses with no fields #15748

Closed
hamdanal opened this issue Jul 22, 2023 · 6 comments · Fixed by #15749
Closed

__match_args__ is not added to dataclasses with no fields #15748

hamdanal opened this issue Jul 22, 2023 · 6 comments · Fixed by #15749
Labels
bug mypy got something wrong topic-dataclasses topic-match-statement Python 3.10's match statement

Comments

@hamdanal
Copy link
Collaborator

Bug Report

stubtest complains about missing __match_args__ if the dataclass has no fields

To Reproduce

Consider this python file:

from dataclasses import dataclass
from typing import ClassVar

@dataclass
class Good:
    x: ClassVar[bool]
    y: int = 0

@dataclass
class Bad:
    x: ClassVar[bool]

and the corresponding stub file

from dataclasses import dataclass
from typing import ClassVar

@dataclass
class Good:
    x: ClassVar[bool]
    y: int = ...

@dataclass
class Bad:
    x: ClassVar[bool]

Expected Behavior

Success: no issues found in 1 module

Actual Behavior

error: t.Bad.__match_args__ is not present in stub
Stub: in file /tmp/st-bug/t.pyi
MISSING
Runtime:
()

Found 1 error (checked 1 module)

Your Environment

  • Mypy version used: mypy 1.4.1 (compiled: yes)
  • Mypy command-line flags: N/A
  • Mypy configuration options from mypy.ini (and other config files): N/A
  • Python version used: 3.10.6
@hamdanal hamdanal added the bug mypy got something wrong label Jul 22, 2023
@AlexWaygood
Copy link
Member

I think this manifests as a stubtest false positive, but the underlying issue is probably that mypy isn't synthesising __match_args__ attributes for dataclasses that have 0 fields

@hamdanal
Copy link
Collaborator Author

Could be from this condition

and attributes

I am not sure why there is a check for attributes here

@AlexWaygood
Copy link
Member

Could be from this condition

Looks like it to me!

I am not sure why there is a check for attributes here

Nor me... want to make a PR? :)

@hamdanal
Copy link
Collaborator Author

Alright, I'll give it a try.

@hamdanal hamdanal changed the title stubtest: False positive for dataclass with no fields __match_args__ is not added to dataclasses with no fields Jul 22, 2023
@hamdanal
Copy link
Collaborator Author

Filed #15749

Seems like the condition was added in the PR #10191 that introduced support for the match statement. This is a huge PR so I didn't follow to see if there is a reason for it or it is just an oversight :)

@AlexWaygood
Copy link
Member

At a guess, I'd imagine it was probably just an oversight :)

@AlexWaygood AlexWaygood added the topic-match-statement Python 3.10's match statement label Jul 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-dataclasses topic-match-statement Python 3.10's match statement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants