-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
bugmypy got something wrongmypy got something wrongpriority-2-lowtopic-ternary-expressiona if b else ca if b else ctopic-type-narrowingConditional type narrowing / binderConditional type narrowing / binder
Description
I saw a bunch of different bugs and chatter for both conditional expressions and but I'm unsure if this behavior is reported on any of them. Apologies if this is noise.
This is with mypy 0.761 (with no arguments) on Python 3.7.3, inline:
foo: Union[int, Callable[[Any], int]]
bar: Callable[[Any], int]
foo = lambda _: 0
# case A
# no errors:
if callable(foo):
bar = foo
else:
bar = lambda _: foo
# case B
# error: Incompatible return value type (got "Union[int, Callable[[int], int]]", expected "int")
bar = foo if callable(foo) else lambda _: fooSo it seems the behavior differs on whether the if is inline, which I found really surprising.
[Separately, setting foo to 0 also fails -- but on both of those cases, which I suppose would be a limitation, rather than a bug]
mplanchard and glroman
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongpriority-2-lowtopic-ternary-expressiona if b else ca if b else ctopic-type-narrowingConditional type narrowing / binderConditional type narrowing / binder