-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
false-positivemypy gave an error on correct codemypy gave an error on correct codeneeds discussionpriority-1-normaltopic-join-v-unionUsing join vs. using unionsUsing join vs. using unionstopic-protocolstopic-ternary-expressiona if b else ca if b else c
Description
python/typeshed#2323 exposed a problem with mypy's (lack of) handling of protocols in ... if ... else ... constructs. Please consider:
from typing import SupportsFloat
class Floaty:
def __float__(self): ...
class Supporter(SupportsFloat):
def __float__(self): ...
reveal_type(Floaty() if bool() else 0)
reveal_type(Supporter() if bool() else 0)
This will reveal the type of the first expression to be builtins.object, while the latter is typing.SupportsFloat. This means that mypy (tested with 0.620, Python 3.7.0) will reject, for example float(Floaty() if bool() else 0).
zero323 and vbrozik
Metadata
Metadata
Assignees
Labels
false-positivemypy gave an error on correct codemypy gave an error on correct codeneeds discussionpriority-1-normaltopic-join-v-unionUsing join vs. using unionsUsing join vs. using unionstopic-protocolstopic-ternary-expressiona if b else ca if b else c