@@ -880,7 +880,7 @@ from typing_extensions import reveal_type
880880def _ (a : int | None ):
881881 reveal_type(
882882 # error: [no-matching-overload]
883- # revealed: Unknown
883+ # revealed: Any
884884 f(
885885 A(),
886886 a1 = a,
@@ -1231,8 +1231,8 @@ def _(list_int: list[int], list_any: list[Any]):
12311231 # All materializations of `list[Any]` are assignable to `list[int]` and `list[Any]`, but the
12321232 # return type of first and second overloads are not equivalent, so the overload matching
12331233 # is ambiguous.
1234- reveal_type(f(list_any)) # revealed: Unknown
1235- reveal_type(f(* (list_any,))) # revealed: Unknown
1234+ reveal_type(f(list_any)) # revealed: Any
1235+ reveal_type(f(* (list_any,))) # revealed: Any
12361236```
12371237
12381238### Single tuple argument
@@ -1277,8 +1277,8 @@ def _(int_str: tuple[int, str], int_any: tuple[int, Any], any_any: tuple[Any, An
12771277
12781278 # All materializations of `tuple[Any, Any]` are assignable to the parameters of all the
12791279 # overloads, but the return types aren't equivalent, so the overload matching is ambiguous
1280- reveal_type(f(any_any)) # revealed: Unknown
1281- reveal_type(f(* (any_any,))) # revealed: Unknown
1280+ reveal_type(f(any_any)) # revealed: Any
1281+ reveal_type(f(* (any_any,))) # revealed: Any
12821282```
12831283
12841284### ` Unknown ` passed into an overloaded function annotated with protocols
@@ -1309,15 +1309,15 @@ def f(a: Foo, b: list[str], c: list[LiteralString], e):
13091309 reveal_type(a.join(b)) # revealed: str
13101310 reveal_type(a.join(c)) # revealed: LiteralString
13111311
1312- # since both overloads match and they have return types that are not equivalent,
1312+ # Since both overloads match and they have return types that are not equivalent,
13131313 # step (5) of the overload evaluation algorithm says we must evaluate the result of the
1314- # call as `Unknown `.
1314+ # call as `Any `.
13151315 #
13161316 # Note: although the spec does not state as such (since intersections in general are not
13171317 # specified currently), `(str | LiteralString) & Unknown` might also be a reasonable type
13181318 # here (the union of all overload returns, intersected with `Unknown`) -- here that would
13191319 # simplify to `str & Unknown`.
1320- reveal_type(a.join(e)) # revealed: Unknown
1320+ reveal_type(a.join(e)) # revealed: Any
13211321```
13221322
13231323### Multiple arguments
@@ -1367,8 +1367,8 @@ def _(list_int: list[int], list_any: list[Any], int_str: tuple[int, str], int_an
13671367 # All materializations of first argument is assignable to the second overload and for the second
13681368 # argument, they're assignable to the third overload, so no overloads are filtered out; the
13691369 # return types of the remaining overloads are not equivalent, so overload matching is ambiguous
1370- reveal_type(f(list_int, any_any)) # revealed: Unknown
1371- reveal_type(f(* (list_int, any_any))) # revealed: Unknown
1370+ reveal_type(f(list_int, any_any)) # revealed: Any
1371+ reveal_type(f(* (list_int, any_any))) # revealed: Any
13721372```
13731373
13741374### ` LiteralString ` and ` str `
@@ -1400,8 +1400,8 @@ def _(literal: LiteralString, string: str, any: Any):
14001400
14011401 # `Any` matches both overloads, but the return types are not equivalent.
14021402 # Pyright and mypy both reveal `str` here, contrary to the spec.
1403- reveal_type(f(any )) # revealed: Unknown
1404- reveal_type(f(* (any ,))) # revealed: Unknown
1403+ reveal_type(f(any )) # revealed: Any
1404+ reveal_type(f(* (any ,))) # revealed: Any
14051405```
14061406
14071407### Generics
@@ -1436,11 +1436,11 @@ def _(list_int: list[int], list_str: list[str], list_any: list[Any], any: Any):
14361436 reveal_type(f(list_str)) # revealed: str
14371437 reveal_type(f(* (list_str,))) # revealed: str
14381438
1439- reveal_type(f(list_any)) # revealed: Unknown
1440- reveal_type(f(* (list_any,))) # revealed: Unknown
1439+ reveal_type(f(list_any)) # revealed: Any
1440+ reveal_type(f(* (list_any,))) # revealed: Any
14411441
1442- reveal_type(f(any )) # revealed: Unknown
1443- reveal_type(f(* (any ,))) # revealed: Unknown
1442+ reveal_type(f(any )) # revealed: Any
1443+ reveal_type(f(* (any ,))) # revealed: Any
14441444```
14451445
14461446### Generics (multiple arguments)
@@ -1513,7 +1513,45 @@ def _(a_int: A[int], a_str: A[str], a_any: A[Any]):
15131513def _ (b_int : B[int ], b_str : B[str ], b_any : B[Any]):
15141514 reveal_type(b_int.method()) # revealed: int
15151515 reveal_type(b_str.method()) # revealed: str
1516- reveal_type(b_any.method()) # revealed: Unknown
1516+ reveal_type(b_any.method()) # revealed: Any
1517+ ```
1518+
1519+ ### Ambiguous ` Any ` overloads (multiple arguments)
1520+
1521+ ``` toml
1522+ [environment ]
1523+ python-version = " 3.12"
1524+ ```
1525+
1526+ ` overloaded.pyi ` :
1527+
1528+ ``` pyi
1529+ from typing import Any, overload
1530+
1531+ class A[T]:
1532+ def get (self ) -> T: ...
1533+
1534+ @overload
1535+ def op (l : A[None ], r : A[None ]) -> A[None ]: ...
1536+ @overload
1537+ def op (l : A[None ], r : A[Any]) -> A[None ]: ...
1538+ @overload
1539+ def op (l : A[Any], r : A[None ]) -> A[None ]: ...
1540+ @overload
1541+ def op (l : A[Any], r : A[Any]) -> A[Any]: ...
1542+ ```
1543+
1544+ ``` py
1545+ from typing import Any, assert_type
1546+
1547+ from overloaded import A, op
1548+
1549+ def _ (x : A[None ], y : A[Any]) -> None :
1550+ assert_type(op(x, x), A[None ])
1551+ assert_type(op(x, y), A[None ])
1552+ assert_type(op(y, x), A[None ])
1553+ assert_type(op(y, y), Any)
1554+ reveal_type(op(y, y)) # revealed: Any
15171555```
15181556
15191557### Variadic argument
@@ -1557,11 +1595,11 @@ def _(arg: list[Any]):
15571595 # Matches both overload and the return types are equivalent
15581596 reveal_type(f1(* arg)) # revealed: A
15591597 # Matches both overload but the return types aren't equivalent
1560- reveal_type(f2(* arg)) # revealed: Unknown
1598+ reveal_type(f2(* arg)) # revealed: Any
15611599 # Filters out the final overload and the return types are equivalent
15621600 reveal_type(f3(* arg)) # revealed: A
15631601 # Filters out the final overload but the return types aren't equivalent
1564- reveal_type(f4(* arg)) # revealed: Unknown
1602+ reveal_type(f4(* arg)) # revealed: Any
15651603```
15661604
15671605### Varidic argument with generics
@@ -1620,15 +1658,15 @@ def _(args1: list[int], args2: list[Any]):
16201658reveal_type(f2()) # revealed: tuple[Any, ...]
16211659reveal_type(f2(1 , 2 )) # revealed: tuple[Literal[1], Literal[2]]
16221660# TODO : Should be `tuple[Literal[1], Literal[2]]`
1623- reveal_type(f2(x1 = 1 , x2 = 2 )) # revealed: Unknown
1661+ reveal_type(f2(x1 = 1 , x2 = 2 )) # revealed: Any
16241662# TODO : Should be `tuple[Literal[2], Literal[1]]`
1625- reveal_type(f2(x2 = 1 , x1 = 2 )) # revealed: Unknown
1663+ reveal_type(f2(x2 = 1 , x1 = 2 )) # revealed: Any
16261664reveal_type(f2(1 , 2 , z = 3 )) # revealed: tuple[Any, ...]
16271665
16281666reveal_type(f3(1 , 2 )) # revealed: tuple[Literal[1], Literal[2]]
16291667reveal_type(f3(1 , 2 , 3 )) # revealed: tuple[Any, ...]
16301668# TODO : Should be `tuple[Literal[1], Literal[2]]`
1631- reveal_type(f3(x1 = 1 , x2 = 2 )) # revealed: Unknown
1669+ reveal_type(f3(x1 = 1 , x2 = 2 )) # revealed: Any
16321670reveal_type(f3(z = 1 )) # revealed: dict[str, Any]
16331671
16341672# error: [no-matching-overload]
@@ -1785,8 +1823,8 @@ from typing import Any
17851823from overloaded import A, B, C, f
17861824
17871825def _ (arg : tuple[A | B, Any]):
1788- reveal_type(f(arg)) # revealed: A | Unknown
1789- reveal_type(f(* (arg,))) # revealed: A | Unknown
1826+ reveal_type(f(arg)) # revealed: A | Any
1827+ reveal_type(f(* (arg,))) # revealed: A | Any
17901828```
17911829
17921830#### Both argument lists ambiguous
@@ -1819,8 +1857,8 @@ from typing import Any
18191857from overloaded import A, B, C, f
18201858
18211859def _ (arg : tuple[A | B, Any]):
1822- reveal_type(f(arg)) # revealed: Unknown
1823- reveal_type(f(* (arg,))) # revealed: Unknown
1860+ reveal_type(f(arg)) # revealed: Any
1861+ reveal_type(f(* (arg,))) # revealed: Any
18241862```
18251863
18261864### Unknown argument with TypeVar overload
@@ -1850,10 +1888,10 @@ from nonexistent_module import something_unknown # error: [unresolved-import]
18501888
18511889reveal_type(something_unknown) # revealed: Unknown
18521890
1853- # The result should be `Unknown `, not `Literal[b""]`.
1854- reveal_type(f(something_unknown)) # revealed: Unknown
1855- reveal_type(f((something_unknown, something_unknown, something_unknown))) # revealed: Unknown
1856- reveal_type(f((something_unknown, None , something_unknown))) # revealed: Unknown
1891+ # The result should be `Any `, not `Literal[b""]`.
1892+ reveal_type(f(something_unknown)) # revealed: Any
1893+ reveal_type(f((something_unknown, something_unknown, something_unknown))) # revealed: Any
1894+ reveal_type(f((something_unknown, None , something_unknown))) # revealed: Any
18571895
18581896# Concrete arguments should still resolve correctly.
18591897def _ (s : str ):
0 commit comments