-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
bugmypy got something wrongmypy got something wrongtopic-type-narrowingConditional type narrowing / binderConditional type narrowing / binder
Description
Bug Report
Type of a.foo in the example below is narrowed to what looks like a function type which results in a strange error on the call to append later.
Issue started with ad30be8 @hauntsaninja
To Reproduce
from typing import Any
def f(a: Any, x: Any) -> None:
if x is not list:
x = []
reveal_type(x) # note: Revealed type is "Any"
if a.foo is not list:
a.foo = []
reveal_type(a.foo) # note: Revealed type is "Any | Overload(def [_T] () -> builtins.list[_T`1], def [_T] (typing.Iterable[_T`1]) -> builtins.list[_T`1])"
a.foo.append(x) # error: Too few arguments for "append" of "list" [call-arg]Expected Behavior
a.foo should probably be typed as Any.
Actual Behavior
/Users/psawicki/test.py:6: note: Revealed type is "Any"
/Users/psawicki/test.py:9: note: Revealed type is "Any | Overload(def [_T] () -> builtins.list[_T`1], def [_T] (typing.Iterable[_T`1]) -> builtins.list[_T`1])"
/Users/psawicki/test.py:10: error: Too few arguments for "append" of "list" [call-arg]
Your Environment
- Mypy version used: mypy 1.20.0+dev.ad30be89f146adaae398bd854146952158a53cad and up
- Mypy command-line flags:
mypy ~/test.py - Mypy configuration options from
mypy.ini(and other config files): None - Python version used: 3.13.5
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-type-narrowingConditional type narrowing / binderConditional type narrowing / binder