@@ -1276,7 +1276,7 @@ def f(x: object) -> object: ...
1276
1276
def f(x): pass
1277
1277
1278
1278
a: Any
1279
- reveal_type(f(a)) # E: Revealed type is 'Any '
1279
+ reveal_type(f(a)) # E: Revealed type is 'builtins.object '
1280
1280
1281
1281
[case testOverloadWithOverlappingItemsAndAnyArgument2]
1282
1282
from typing import overload, Any
@@ -1288,7 +1288,7 @@ def f(x: float) -> float: ...
1288
1288
def f(x): pass
1289
1289
1290
1290
a: Any
1291
- reveal_type(f(a)) # E: Revealed type is 'Any '
1291
+ reveal_type(f(a)) # E: Revealed type is 'builtins.float '
1292
1292
1293
1293
[case testOverloadWithOverlappingItemsAndAnyArgument3]
1294
1294
from typing import overload, Any
@@ -1313,15 +1313,15 @@ def f(x): pass
1313
1313
1314
1314
a: Any
1315
1315
# Any causes ambiguity
1316
- reveal_type(f(a, 1, '')) # E: Revealed type is 'Any '
1316
+ reveal_type(f(a, 1, '')) # E: Revealed type is 'builtins.object '
1317
1317
# Any causes no ambiguity
1318
1318
reveal_type(f(1, a, a)) # E: Revealed type is 'builtins.int'
1319
1319
reveal_type(f('', a, a)) # E: Revealed type is 'builtins.object'
1320
1320
# Like above, but use keyword arguments.
1321
- reveal_type(f(y=1, z='', x=a)) # E: Revealed type is 'Any '
1321
+ reveal_type(f(y=1, z='', x=a)) # E: Revealed type is 'builtins.object '
1322
1322
reveal_type(f(y=a, z='', x=1)) # E: Revealed type is 'builtins.int'
1323
1323
reveal_type(f(z='', x=1, y=a)) # E: Revealed type is 'builtins.int'
1324
- reveal_type(f(z='', x=a, y=1)) # E: Revealed type is 'Any '
1324
+ reveal_type(f(z='', x=a, y=1)) # E: Revealed type is 'builtins.object '
1325
1325
1326
1326
[case testOverloadWithOverlappingItemsAndAnyArgument5]
1327
1327
from typing import overload, Any, Union
@@ -1333,7 +1333,7 @@ def f(x: Union[int, float]) -> float: ...
1333
1333
def f(x): pass
1334
1334
1335
1335
a: Any
1336
- reveal_type(f(a)) # E: Revealed type is 'Any '
1336
+ reveal_type(f(a)) # E: Revealed type is 'builtins.float '
1337
1337
1338
1338
[case testOverloadWithOverlappingItemsAndAnyArgument6]
1339
1339
from typing import overload, Any
@@ -1343,7 +1343,7 @@ def f(x: int, y: int) -> int: ...
1343
1343
@overload
1344
1344
def f(x: float, y: int, z: str) -> float: ...
1345
1345
@overload
1346
- def f(x: object, y: int, z: str, a: None) -> object : ...
1346
+ def f(x: object, y: int, z: str, a: None) -> str : ...
1347
1347
def f(x): pass
1348
1348
1349
1349
a: Any
@@ -1352,7 +1352,7 @@ reveal_type(f(*a)) # E: Revealed type is 'Any'
1352
1352
reveal_type(f(a, *a)) # E: Revealed type is 'Any'
1353
1353
reveal_type(f(1, *a)) # E: Revealed type is 'Any'
1354
1354
reveal_type(f(1.1, *a)) # E: Revealed type is 'Any'
1355
- reveal_type(f('', *a)) # E: Revealed type is 'builtins.object '
1355
+ reveal_type(f('', *a)) # E: Revealed type is 'builtins.str '
1356
1356
1357
1357
[case testOverloadWithOverlappingItemsAndAnyArgument7]
1358
1358
from typing import overload, Any
@@ -1365,7 +1365,7 @@ def f(x): pass
1365
1365
1366
1366
a: Any
1367
1367
# TODO: We could infer 'int' here
1368
- reveal_type(f(1, *a)) # E: Revealed type is 'Any '
1368
+ reveal_type(f(1, *a)) # E: Revealed type is 'builtins.object '
1369
1369
1370
1370
[case testOverloadWithOverlappingItemsAndAnyArgument8]
1371
1371
from typing import overload, Any
@@ -1381,6 +1381,26 @@ a: Any
1381
1381
reveal_type(f(a, 1, 1)) # E: Revealed type is 'builtins.str'
1382
1382
reveal_type(f(1, *a)) # E: Revealed type is 'builtins.str'
1383
1383
1384
+ [case testOverloadWithOverlappingItemsAndAnyArgument9]
1385
+ from typing import overload, Any, List
1386
+
1387
+ @overload
1388
+ def f(x: List[int]) -> List[int]: ...
1389
+ @overload
1390
+ def f(x: List[Any]) -> List[Any]: ...
1391
+ def f(x): pass
1392
+
1393
+ a: Any
1394
+ b: List[Any]
1395
+ c: List[str]
1396
+ d: List[int]
1397
+ reveal_type(f(a)) # E: Revealed type is 'builtins.list[Any]'
1398
+ reveal_type(f(b)) # E: Revealed type is 'builtins.list[Any]'
1399
+ reveal_type(f(c)) # E: Revealed type is 'builtins.list[Any]'
1400
+ reveal_type(f(d)) # E: Revealed type is 'builtins.list[builtins.int]'
1401
+
1402
+ [builtins fixtures/list.pyi]
1403
+
1384
1404
[case testOverloadOnOverloadWithType]
1385
1405
from typing import Any, Type, TypeVar, overload
1386
1406
from mod import MyInt
@@ -1723,6 +1743,105 @@ def foo2(**kwargs: int) -> str: ...
1723
1743
def foo2(*args: int) -> int: ... # E: Overloaded function signature 2 will never be matched: function 1's parameter type(s) are the same or broader
1724
1744
[builtins fixtures/dict.pyi]
1725
1745
1746
+ [case testOverloadVarargInputAndVarargDefinition]
1747
+ from typing import overload, List
1748
+
1749
+ class A: ...
1750
+ class B: ...
1751
+ class C: ...
1752
+
1753
+ @overload
1754
+ def foo(x: int) -> A: ...
1755
+ @overload
1756
+ def foo(x: int, y: int) -> B: ...
1757
+ @overload
1758
+ def foo(x: int, y: int, z: int, *args: int) -> C: ...
1759
+ def foo(*args): pass
1760
+
1761
+ reveal_type(foo(1)) # E: Revealed type is '__main__.A'
1762
+ reveal_type(foo(1, 2)) # E: Revealed type is '__main__.B'
1763
+ reveal_type(foo(1, 2, 3)) # E: Revealed type is '__main__.C'
1764
+
1765
+ reveal_type(foo(*[1])) # E: Revealed type is '__main__.C'
1766
+ reveal_type(foo(*[1, 2])) # E: Revealed type is '__main__.C'
1767
+ reveal_type(foo(*[1, 2, 3])) # E: Revealed type is '__main__.C'
1768
+
1769
+ x: List[int]
1770
+ reveal_type(foo(*x)) # E: Revealed type is '__main__.C'
1771
+
1772
+ y: List[str]
1773
+ foo(*y) # E: No overload variant of "foo" matches argument type "List[str]"
1774
+ [builtins fixtures/list.pyi]
1775
+
1776
+ [case testOverloadMultipleVarargDefinition]
1777
+ from typing import overload, List, Any
1778
+
1779
+ class A: ...
1780
+ class B: ...
1781
+ class C: ...
1782
+ class D: ...
1783
+
1784
+ @overload
1785
+ def foo(x: int) -> A: ...
1786
+ @overload
1787
+ def foo(x: int, y: int) -> B: ...
1788
+ @overload
1789
+ def foo(x: int, y: int, z: int, *args: int) -> C: ...
1790
+ @overload
1791
+ def foo(*x: str) -> D: ...
1792
+ def foo(*args): pass
1793
+
1794
+ reveal_type(foo(*[1, 2])) # E: Revealed type is '__main__.C'
1795
+ reveal_type(foo(*["a", "b"])) # E: Revealed type is '__main__.D'
1796
+
1797
+ x: List[Any]
1798
+ reveal_type(foo(*x)) # E: Revealed type is 'Any'
1799
+ [builtins fixtures/list.pyi]
1800
+
1801
+ [case testOverloadMultipleVarargDefinitionComplex]
1802
+ from typing import TypeVar, overload, Any, Callable
1803
+
1804
+ T1 = TypeVar('T1')
1805
+ T2 = TypeVar('T2')
1806
+ T3 = TypeVar('T3')
1807
+
1808
+ @overload
1809
+ def chain_call(input_value: T1,
1810
+ f1: Callable[[T1], T2]) -> T2: ...
1811
+ @overload
1812
+ def chain_call(input_value: T1,
1813
+ f1: Callable[[T1], T2],
1814
+ f2: Callable[[T2], T3]) -> T3: ...
1815
+ @overload
1816
+ def chain_call(input_value: T1,
1817
+ *f_rest: Callable[[T1], T1]) -> T1: ...
1818
+ @overload
1819
+ def chain_call(input_value: T1,
1820
+ f1: Callable[[T1], T2],
1821
+ f2: Callable[[T2], T3],
1822
+ f3: Callable[[T3], Any],
1823
+ *f_rest: Callable[[Any], Any]) -> Any: ...
1824
+ def chain_call(input_value, *f_rest):
1825
+ for function in f_rest:
1826
+ input_value = function(input_value)
1827
+ return input_value
1828
+
1829
+
1830
+ class A: ...
1831
+ class B: ...
1832
+ class C: ...
1833
+ class D: ...
1834
+
1835
+ def f(x: A) -> A: ...
1836
+ def f1(x: A) -> B: ...
1837
+ def f2(x: B) -> C: ...
1838
+ def f3(x: C) -> D: ...
1839
+
1840
+ reveal_type(chain_call(A(), f1, f2)) # E: Revealed type is '__main__.C*'
1841
+ reveal_type(chain_call(A(), f1, f2, f3)) # E: Revealed type is 'Any'
1842
+ reveal_type(chain_call(A(), f, f, f, f)) # E: Revealed type is '__main__.A'
1843
+ [builtins fixtures/list.pyi]
1844
+
1726
1845
[case testOverloadWithPartiallyOverlappingUnions]
1727
1846
from typing import overload, Union
1728
1847
0 commit comments