-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
bugmypy got something wrongmypy got something wrongtopic-type-narrowingConditional type narrowing / binderConditional type narrowing / binder
Description
Bug Report
Hey there!
I have recently encountered this case:
class Animal:
name: Literal["animal"]
n_legs: int
class Plant:
name: Literal["plant"]
def get_n_legs(item: Union[Animal, Plant]):
if item.name == "animal" and item.n_legs > 6: # This fails mypy with union-attr for n_legs in Plant
return "Many"
Expected Behavior
Mypy should be able to narrow down chained conditionals as presented. It seems that pylance has no problems with it, for example.
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-type-narrowingConditional type narrowing / binderConditional type narrowing / binder