Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mypy/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def _infer_constraints(
infer_constraints_if_possible(t_item, actual, direction)
for t_item in template.items
],
eager=False,
eager=isinstance(actual, AnyType),
)
if result:
return result
Expand Down
10 changes: 10 additions & 0 deletions test-data/unit/check-inference.test
Original file line number Diff line number Diff line change
Expand Up @@ -4071,3 +4071,13 @@ def check_or_nested(maybe: bool) -> None:
reveal_type(foo) # N: Revealed type is "builtins.list[builtins.int]"
reveal_type(bar) # N: Revealed type is "builtins.list[builtins.int]"
reveal_type(baz) # N: Revealed type is "builtins.list[builtins.int]"

[case testInferOptionalAgainstAny]
from typing import Any, Optional, TypeVar

a: Any
oa: Optional[Any]
T = TypeVar("T")
def f(x: Optional[T]) -> T: ...
reveal_type(f(a)) # N: Revealed type is "Any"
reveal_type(f(oa)) # N: Revealed type is "Any"