@@ -6857,10 +6857,9 @@ if isinstance(headers, dict):
68576857reveal_type(headers) # N: Revealed type is "__main__.Headers | typing.Iterable[tuple[builtins.bytes, builtins.bytes]]"
68586858[builtins fixtures/isinstancelist.pyi]
68596859
6860- [case testOverloadAliasToAnyArgWithNoneDefault]
6861- # An alias `Incomplete = Any` used as an overload arg must not silently match
6862- # the `default: None = None` overload. It should be treated as Any like a bare
6863- # Any value, triggering the overload-ambiguity fallback.
6860+ [case testOverloadAliasToAnyArg]
6861+ # An alias `Incomplete = Any` used as an overload arg should behave like bare
6862+ # Any (engage the ambiguity fallback), not silently match a None-default overload.
68646863from typing import Any, TypeVar, overload
68656864from typing_extensions import TypeAlias
68666865
@@ -6880,120 +6879,48 @@ a: Incomplete
68806879b: Any
68816880reveal_type(M().get("k", a)) # N: Revealed type is "Any"
68826881reveal_type(M().get("k", b)) # N: Revealed type is "Any"
6883- [builtins fixtures/tuple.pyi]
6884-
6885- [case testOverloadAliasToAnyArgEquivalentToBareAny]
6886- # Alias-to-Any and bare Any should produce the same overload results.
6887- from typing import Any, overload
6888- from typing_extensions import TypeAlias
6889-
6890- Incomplete: TypeAlias = Any
68916882
6883+ # Unambiguous overload: alias-Any picks the matching return type, no false ambiguity.
68926884@overload
6893- def f(x: int) -> int: ...
6885+ def f(x: int, y: int ) -> int: ...
68946886@overload
6895- def f(x: str ) -> str : ...
6896- def f(x): ...
6887+ def f(x: object, y: int ) -> object : ...
6888+ def f(x, y ): ...
68976889
6898- a: Incomplete
6899- b: Any
6900- reveal_type(f(a)) # N: Revealed type is "Any"
6901- reveal_type(f(b)) # N: Revealed type is "Any"
6890+ reveal_type(f(1, a)) # N: Revealed type is "builtins.int"
69026891[builtins fixtures/tuple.pyi]
69036892
6904- [case testOverloadAliasToAnyArgChainedAlias]
6905- # A chained alias `Outer = Inner` where `Inner = Any` should still behave
6906- # like Any, both at the inner and outer level.
6907- from typing import Any, overload
6893+ [case testAliasToAnyDoesNotTriggerDisallowAnyExplicitAtUseSite]
6894+ # flags: --disallow-any-explicit --show-error-codes
6895+ from typing import Any
69086896from typing_extensions import TypeAlias
69096897
6910- Inner: TypeAlias = Any
6911- Outer: TypeAlias = Inner
6912-
6913- @overload
6914- def f(x: int) -> int: ...
6915- @overload
6916- def f(x: str) -> str: ...
6917- def f(x): ...
6918-
6919- inner: Inner
6920- outer: Outer
6921- reveal_type(f(inner)) # N: Revealed type is "Any"
6922- reveal_type(f(outer)) # N: Revealed type is "Any"
6923- [builtins fixtures/tuple.pyi]
6924-
6925- [case testOverloadAliasToAnyArgImplicitAlias]
6926- # `MyAlias = Any` without an explicit TypeAlias annotation also gets the
6927- # alias-Any treatment and must engage the overload-ambiguity check.
6928- from typing import Any, overload
6929-
6930- MyAlias = Any
6931-
6932- @overload
6933- def f(x: int) -> int: ...
6934- @overload
6935- def f(x: str) -> str: ...
6936- def f(x): ...
6937-
6938- a: MyAlias
6939- reveal_type(f(a)) # N: Revealed type is "Any"
6940- [builtins fixtures/tuple.pyi]
6941-
6942- [case testOverloadAliasToAnyArgImported]
6943- # Alias-to-Any imported from another module must behave the same way.
6944- from typing import overload
6945- from other import Incomplete
6946-
6947- @overload
6948- def f(x: int) -> int: ...
6949- @overload
6950- def f(x: str) -> str: ...
6951- def f(x): ...
6898+ Incomplete: TypeAlias = Any # E: Explicit "Any" is not allowed [explicit-any]
69526899
6953- a : Incomplete
6954- reveal_type(f(a)) # N: Revealed type is "Any"
6900+ def f(x : Incomplete) -> Incomplete: # no error
6901+ return x
69556902
6956- [file other.py]
6957- from typing import Any
6958- from typing_extensions import TypeAlias
6959- Incomplete: TypeAlias = Any
6903+ a: Incomplete = 1 # no error
69606904[builtins fixtures/tuple.pyi]
69616905
6962- [case testOverloadAliasToAnyArgUnambiguous ]
6963- # When overloads are unambiguous, alias-to-Any should pick that overload's
6964- # return type just like bare Any does (no false ambiguity) .
6965- from typing import Any, overload
6906+ [case testOverloadNestedAnyDoesNotTriggerAmbiguity ]
6907+ # Any (explicit or alias-to-Any) nested inside a generic argument should not
6908+ # trigger the overload-ambiguity fallback — only a top-level Any actual arg counts .
6909+ from typing import Any, Generic, TypeVar, overload
69666910from typing_extensions import TypeAlias
69676911
6912+ T = TypeVar("T")
69686913Incomplete: TypeAlias = Any
69696914
6970- @overload
6971- def f(x: int, y: int, z: str) -> int: ...
6972- @overload
6973- def f(x: object, y: int, z: str) -> object: ...
6974- def f(x, y, z): ...
6975-
6976- a: Incomplete
6977- b: Any
6978- # Ambiguous on x: returns Any
6979- reveal_type(f(a, 1, '')) # N: Revealed type is "Any"
6980- reveal_type(f(b, 1, '')) # N: Revealed type is "Any"
6981- # Unambiguous: x is concrete, only y/z are Any
6982- reveal_type(f(1, a, '')) # N: Revealed type is "builtins.int"
6983- reveal_type(f(1, b, '')) # N: Revealed type is "builtins.int"
6984- [builtins fixtures/tuple.pyi]
6915+ class Array(Generic[T]): pass
69856916
6986- [case testAliasToAnyDoesNotTriggerDisallowAnyExplicitAtUseSite]
6987- # --disallow-any-explicit must NOT fire at use sites of an `Alias = Any`
6988- # (the original purpose of make_any_non_explicit).
6989- # flags: --disallow-any-explicit --show-error-codes
6990- from typing import Any
6991- from typing_extensions import TypeAlias
6992-
6993- Incomplete: TypeAlias = Any # E: Explicit "Any" is not allowed [explicit-any]
6994-
6995- def f(x: Incomplete) -> Incomplete: # no error
6996- return x
6917+ class Series(Generic[T]):
6918+ @overload
6919+ def __add__(self: Series[bool], other: Array[Any]) -> Series[bool]: ...
6920+ @overload
6921+ def __add__(self: Series[T], other: Array[Any]) -> Series[T]: ...
6922+ def __add__(self, other): ...
69976923
6998- a: Incomplete = 1 # no error
6924+ def f(x: Series[Any], y: Array[Incomplete]) -> None:
6925+ reveal_type(x + y) # N: Revealed type is "__main__.Series[builtins.bool]"
69996926[builtins fixtures/tuple.pyi]
0 commit comments