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

Positional subpattern of a built-in type subclass with __match_args__ causes type confusion #18140

Closed
mgedmin opened this issue Nov 10, 2024 · 0 comments · Fixed by #18141
Closed
Labels
bug mypy got something wrong topic-match-statement Python 3.10's match statement

Comments

@mgedmin
Copy link
Contributor

mgedmin commented Nov 10, 2024

Given

class PrintableKey(bytes):
    __match_args__ = ('ch', )

    @property
    def ch(self) -> str:
        return self.decode('UTF-8')

now

match event:
    case PrintableKey(ch):
        reveal_type(ch)  # mypy thinks it's PrintableKey

versus

match event:
    case PrintableKey(ch=ch):
        reveal_type(ch)  # mypy correctly deduces it's str

Originally posted by @mgedmin in #13804 (comment)

@mgedmin mgedmin changed the title Positional subpattern of a built-in type subclass with __match_args__ causes type confusin Positional subpattern of a built-in type subclass with __match_args__ causes type confusion Nov 10, 2024
@brianschubert brianschubert added bug mypy got something wrong topic-match-statement Python 3.10's match statement labels Nov 10, 2024
@JukkaL JukkaL closed this as completed in 54a2c6d Nov 11, 2024
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-match-statement Python 3.10's match statement
Projects
None yet
2 participants