-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed as not planned
Labels
bugmypy got something wrongmypy got something wrong
Description
Bug Report
Hello Mypy friends!
While playing around with yet another proposal for sum types (typing-sig message forthcoming), I think I found a small issue with attrs and the match statement.
To Reproduce
from typing import Generic, TypeVar
from attrs import frozen
from typing_extensions import assert_never
T = TypeVar("T")
@frozen
class Some(Generic[T]):
val: TExpected and Actual Behavior
Now we define a function that handles it.
def takes_opt(opt: Some[int]) -> None:
match opt:
case Some(val):
reveal_type(opt) # Correct, Some[int]
reveal_type(opt.val) # Correct, int
reveal_type(val) # Incorrect, Any
pass
case _:
assert_never(opt)So I'm going to guess it's an issue with how we generate attrs __match_args__, maybe for generic types. I might try solving this myself, or it would be awesome if someone more knowledgeable could solve it first.
If I use dataclasses it works properly.
Your Environment
- Mypy version used: mypy 0.982 (compiled: yes)
- Mypy command-line flags:
- Mypy configuration options from
mypy.ini(and other config files): - Python version used: Python 3.10.6
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrong