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

mypy generates __match_args__ for dataclasses and NamedTuples on Python <3.10 #12489

Closed
AlexWaygood opened this issue Mar 29, 2022 · 6 comments · Fixed by #12503
Closed

mypy generates __match_args__ for dataclasses and NamedTuples on Python <3.10 #12489

AlexWaygood opened this issue Mar 29, 2022 · 6 comments · Fixed by #12503
Labels
bug mypy got something wrong good-first-issue priority-2-low topic-dataclasses topic-match-statement Python 3.10's match statement topic-named-tuple topic-runtime-semantics mypy doesn't model runtime semantics correctly

Comments

@AlexWaygood
Copy link
Member

AlexWaygood commented Mar 29, 2022

Bug Report

Not a big deal, but mypy appears to generate __match_args__ for dataclasses and NamedTuples even when running with --python-version set to 3.9:

from dataclasses import dataclass
from typing import NamedTuple

@dataclass
class One:
    bar: int

f: One
reveal_type(f.__match_args__)  # Revealed type is "Tuple[Literal['bar']]"

class Two(NamedTuple):
    baz: str

g: Two
reveal_type(g.__match_args__)  # Revealed type is "Tuple[Literal['baz']]"

Expected Behavior

Mypy should not autogenerate __match_args__ when running with --python-version set to <3.10, as pattern-matching is new in 3.10.

Your Environment

  • Mypy version used: 0.950+dev.a33d2353a81d075850a487f3913720037f2473aa (compiled: no)
  • Mypy command-line flags: --python-version 3.9
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.10
  • Operating system and version: Windows
@AlexWaygood AlexWaygood added bug mypy got something wrong topic-named-tuple priority-2-low topic-match-statement Python 3.10's match statement topic-dataclasses topic-runtime-semantics mypy doesn't model runtime semantics correctly labels Mar 29, 2022
@jhance
Copy link
Collaborator

jhance commented Mar 30, 2022

This is probably a good issue for someone new to mypy.

@Ryanchou24
Copy link

I am new to mypy and I would like to work on this. I search the code above but was unable to find it. Can someone tells me where should I look at it?

@Ryanchou24
Copy link

WeChatf7ed2091c8aa4e0a785053c9562b96a5

I was wondering that if this solves the problem.

@AlexWaygood
Copy link
Member Author

WeChatf7ed2091c8aa4e0a785053c9562b96a5

I was wondering that if this solves the problem.

I haven't looked at the code in depth, but that looks promising!

Pattern-matching support was added in #10191 — if you do a CTRL-F for "dataclasses" and "NamedTuple" in the files-changed tab for that PR, you should be able to find the bits of code that need to be changed 🙂

@Loriasun
Copy link

Hi, there I am wondering if I can work on this one?

@AlexWaygood
Copy link
Member Author

AlexWaygood commented Apr 11, 2022

@Loriasun, there's already an open PR for this one (#12503) — it would be better to wait until that has been reviewed before opening another PR for this issue 🙂

JukkaL pushed a commit that referenced this issue Jul 8, 2022
Gobot1234 pushed a commit to Gobot1234/mypy that referenced this issue Aug 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong good-first-issue priority-2-low topic-dataclasses topic-match-statement Python 3.10's match statement topic-named-tuple topic-runtime-semantics mypy doesn't model runtime semantics correctly
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants