-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
topic-join-v-unionUsing join vs. using unionsUsing join vs. using unions
Description
Feature
Mypy should take a note from Pylance and infer more specific types as a result of structural pattern matching.
Pitch
The main example:
class Parent:
pass
class A(Parent):
def do_something(self) -> None:
print("something A-ish")
class B(Parent):
def do_something(self) -> None:
print("something B-ish")
def my_function(val: Parent) -> None:
match val:
case A():
pass
case B():
pass
case Parent():
return
val.do_something() # "Parent" has no attribute "do_something" Mypy(attr-defined)
reveal_type(val)
The result of reveal_type(val) is Parent according to Mypy and A | B according to Pylance. While both of these correctly describe the type of val, the type of A | B is more specific which means the type checker would have no reason to complain about val.do_something().
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
topic-join-v-unionUsing join vs. using unionsUsing join vs. using unions