Skip to content

Commit d70ebaa

Browse files
committed
Merge main to resolve functools regression test import conflict
2 parents 423bc93 + 0069c3c commit d70ebaa

37 files changed

Lines changed: 430 additions & 375 deletions

‎requirements-tests.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
mypy==2.4.0
44
pyrefly==1.3.2
55
pyright==1.1.414
6-
ty==0.0.84
6+
ty==0.0.85
77

88
# Libraries used by our various scripts.
99
aiohttp==3.14.3

‎stdlib/@tests/test_cases/asyncio/check_gather.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import asyncio
4-
from typing import Awaitable, List, Tuple, Union
4+
from collections.abc import Awaitable
55
from typing_extensions import assert_type
66

77

@@ -15,20 +15,20 @@ async def coro2() -> str:
1515

1616
async def test_gather(awaitable1: Awaitable[int], awaitable2: Awaitable[str]) -> None:
1717
a = await asyncio.gather(awaitable1)
18-
assert_type(a, Tuple[int])
18+
assert_type(a, tuple[int])
1919

2020
b = await asyncio.gather(awaitable1, awaitable2, return_exceptions=True)
21-
assert_type(b, Tuple[Union[int, BaseException], Union[str, BaseException]])
21+
assert_type(b, tuple[int | BaseException, str | BaseException])
2222

2323
c = await asyncio.gather(awaitable1, awaitable2, awaitable1, awaitable1, awaitable1, awaitable1)
24-
assert_type(c, Tuple[int, str, int, int, int, int])
24+
assert_type(c, tuple[int, str, int, int, int, int])
2525

2626
d = await asyncio.gather(awaitable1, awaitable1, awaitable1, awaitable1, awaitable1, awaitable1, awaitable1)
27-
assert_type(d, List[int])
27+
assert_type(d, list[int])
2828

2929
awaitables_list: list[Awaitable[int]] = [awaitable1]
3030
e = await asyncio.gather(*awaitables_list)
31-
assert_type(e, List[int])
31+
assert_type(e, list[int])
3232

3333
# this case isn't reliable between typecheckers, no one would ever call it with no args anyway
3434
# f = await asyncio.gather()

‎stdlib/@tests/test_cases/builtins/check_dict.py‎

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from __future__ import annotations
22

33
import os
4-
from typing import Any, Dict, Generic, Iterable, Mapping, TypeVar, Union
4+
from collections.abc import Iterable, Mapping
5+
from typing import Any, Generic, TypeVar
56
from typing_extensions import Self, assert_type
67

78
###################################################################
@@ -15,9 +16,9 @@
1516
# https://github.com/python/mypy/issues/12358
1617
# bad = dict()
1718
good: dict[str, str] = dict()
18-
assert_type(good, Dict[str, str])
19+
assert_type(good, dict[str, str])
1920

20-
assert_type(dict(arg=1), Dict[str, int])
21+
assert_type(dict(arg=1), dict[str, int])
2122

2223
_KT = TypeVar("_KT")
2324
_VT = TypeVar("_VT")
@@ -37,11 +38,11 @@ def __getitem__(self, __k: _KT) -> _VT:
3738

3839

3940
kt1: KeysAndGetItem[int, str] = KeysAndGetItem({0: ""})
40-
assert_type(dict(kt1), Dict[int, str])
41+
assert_type(dict(kt1), dict[int, str])
4142
dict(kt1, arg="a") # type: ignore
4243

4344
kt2: KeysAndGetItem[str, int] = KeysAndGetItem({"": 0})
44-
assert_type(dict(kt2, arg=1), Dict[str, int])
45+
assert_type(dict(kt2, arg=1), dict[str, int])
4546

4647

4748
def test_iterable_tuple_overload(x: Iterable[tuple[int, str]]) -> dict[int, str]:
@@ -53,12 +54,12 @@ def test_iterable_tuple_overload(x: Iterable[tuple[int, str]]) -> dict[int, str]
5354
dict(i1, arg="a") # type: ignore
5455

5556
i2: Iterable[tuple[str, int]] = [("a", 1), ("b", 2)]
56-
assert_type(dict(i2, arg=1), Dict[str, int])
57+
assert_type(dict(i2, arg=1), dict[str, int])
5758

5859
i3: Iterable[str] = ["a.b"]
5960
i4: Iterable[bytes] = [b"a.b"]
60-
assert_type(dict(string.split(".") for string in i3), Dict[str, str])
61-
assert_type(dict(string.split(b".") for string in i4), Dict[bytes, bytes])
61+
assert_type(dict(string.split(".") for string in i3), dict[str, str])
62+
assert_type(dict(string.split(b".") for string in i4), dict[bytes, bytes])
6263

6364
dict(["foo", "bar", "baz"]) # type: ignore
6465
dict([b"foo", b"bar", b"baz"]) # type: ignore
@@ -71,19 +72,19 @@ def test_iterable_tuple_overload(x: Iterable[tuple[int, str]]) -> dict[int, str]
7172
int_value = 1
7273

7374
assert_type(d_any["key"], Any)
74-
assert_type(d_any.get("key"), Union[Any, None])
75-
assert_type(d_any.get("key", None), Union[Any, None])
75+
assert_type(d_any.get("key"), Any | None)
76+
assert_type(d_any.get("key", None), Any | None)
7677
assert_type(d_any.get("key", any_value), Any)
7778
assert_type(d_any.get("key", str_value), Any)
7879
assert_type(d_any.get("key", int_value), Any)
7980

8081
assert_type(d_str["key"], str)
81-
assert_type(d_str.get("key"), Union[str, None])
82-
assert_type(d_str.get("key", None), Union[str, None])
82+
assert_type(d_str.get("key"), str | None)
83+
assert_type(d_str.get("key", None), str | None)
8384
# Pyright has str instead of Any here
8485
assert_type(d_str.get("key", any_value), Any) # pyright: ignore[reportAssertTypeFailure]
8586
assert_type(d_str.get("key", str_value), str)
86-
assert_type(d_str.get("key", int_value), Union[str, int])
87+
assert_type(d_str.get("key", int_value), str | int)
8788

8889
# Now with context!
8990
result: str
@@ -184,16 +185,16 @@ def test_dict_dot_or(
184185
assert_type(a | b, dict[int, int])
185186
assert_type(b | a, dict[int, int])
186187

187-
assert_type(a | c, dict[Union[int, str], Union[int, str]])
188+
assert_type(a | c, dict[int | str, int | str])
188189

189190
# arbitrary mappings are not accepted by `dict.__or__`;
190191
# it has to be a subclass of `dict`
191192
a | d # type: ignore
192193

193194
# but Mappings such as `os._Environ` or `CustomMappingWithDunderOr`,
194195
# which define `__ror__` methods that accept `dict`, are fine:
195-
assert_type(a | os.environ, dict[Union[str, int], Union[str, int]])
196-
assert_type(os.environ | a, dict[Union[str, int], Union[str, int]])
196+
assert_type(a | os.environ, dict[int | str, int | str])
197+
assert_type(os.environ | a, dict[int | str, int | str])
197198

198199
assert_type(c | os.environ, dict[str, str])
199200
assert_type(c | e, dict[str, str])

‎stdlib/@tests/test_cases/builtins/check_list.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
from typing import List, Union
43
from typing_extensions import assert_type
54

65

@@ -16,6 +15,6 @@ def asd(self) -> int:
1615

1716

1817
combined = [Foo()] + [Bar()]
19-
assert_type(combined, List[Union[Foo, Bar]])
18+
assert_type(combined, list[Foo | Bar])
2019
for item in combined:
2120
assert_type(item.asd(), int)

‎stdlib/@tests/test_cases/builtins/check_sum.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from typing import Any, List, Literal, Union
3+
from typing import Any, Literal
44
from typing_extensions import assert_type
55

66

@@ -31,10 +31,10 @@ def __radd__(self, other: Any) -> Baz:
3131
assert_type(sum([True, False], True), int)
3232
assert_type(sum(literal_list), int)
3333

34-
assert_type(sum([["foo"], ["bar"]], ["baz"]), List[str])
34+
assert_type(sum([["foo"], ["bar"]], ["baz"]), list[str])
3535

3636
assert_type(sum([Foo(), Foo()], Foo()), Foo)
37-
assert_type(sum([Baz(), Baz()]), Union[Baz, Literal[0]])
37+
assert_type(sum([Baz(), Baz()]), Baz | Literal[0])
3838

3939
# mypy and pyright infer the types differently for these, so we can't use assert_type
4040
# Just test that no error is emitted for any of these
Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
from __future__ import annotations
22

3-
from typing import Tuple
3+
import sys
4+
from typing import Any
45
from typing_extensions import assert_type
56

67

78
# Empty tuples, see #8275
8-
class TupleSub(Tuple[int, ...]):
9+
class TupleSub(tuple[int, ...]):
910
pass
1011

1112

1213
assert_type(TupleSub(), TupleSub)
1314
assert_type(TupleSub([1, 2, 3]), TupleSub)
15+
16+
# Hashability shenanigans, see #15852
17+
t: tuple[int, int] = (1, 3)
18+
hash(t)
19+
u: tuple[int, ...] = tuple(b"spam")
20+
hash(u)
21+
v: tuple[str] = ("",)
22+
hash(v)
23+
w: tuple[()] = ()
24+
hash(w)
25+
hash(tuple(sys.platform))
26+
x: tuple[Any, Any] = ((), ())
27+
hash(x)
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
from __future__ import annotations
22

3-
from typing import Sequence, Tuple
3+
from collections.abc import Sequence
44
from typing_extensions import assert_type
55

66
ints: Sequence[int] = [1, 2, 3]
77
strs: Sequence[str] = ["one", "two", "three"]
88
floats: Sequence[float] = [1.0, 2.0, 3.0]
9-
str_tuples: Sequence[Tuple[str]] = list((x,) for x in strs)
9+
str_tuples: Sequence[tuple[str]] = list((x,) for x in strs)
1010

11-
assert_type(zip(ints), zip[Tuple[int]])
12-
assert_type(zip(ints, strs), zip[Tuple[int, str]])
13-
assert_type(zip(ints, strs, floats), zip[Tuple[int, str, float]])
14-
assert_type(zip(strs, ints, floats, ints), zip[Tuple[str, int, float, int]])
15-
assert_type(zip(strs, ints, floats, ints, str_tuples), zip[Tuple[str, int, float, int, Tuple[str]]])
11+
assert_type(zip(ints), zip[tuple[int]])
12+
assert_type(zip(ints, strs), zip[tuple[int, str]])
13+
assert_type(zip(ints, strs, floats), zip[tuple[int, str, float]])
14+
assert_type(zip(strs, ints, floats, ints), zip[tuple[str, int, float, int]])
15+
assert_type(zip(strs, ints, floats, ints, str_tuples), zip[tuple[str, int, float, int, tuple[str]]])

‎stdlib/@tests/test_cases/check_dataclasses.py‎

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import dataclasses as dc
44
import sys
5-
from typing import TYPE_CHECKING, Any, Dict, FrozenSet, Tuple, Type, Union
5+
from typing import TYPE_CHECKING, Any
66
from typing_extensions import Annotated, assert_type
77

88
if TYPE_CHECKING:
@@ -14,21 +14,21 @@ class Foo:
1414
attr: str
1515

1616

17-
assert_type(dc.fields(Foo), Tuple[dc.Field[Any], ...])
17+
assert_type(dc.fields(Foo), tuple[dc.Field[Any], ...])
1818

1919
dc.asdict(Foo) # type: ignore
2020
dc.astuple(Foo) # type: ignore
2121
dc.replace(Foo) # type: ignore
2222

2323
# See #9723 for why we can't make this assertion
2424
# if dc.is_dataclass(Foo):
25-
# assert_type(Foo, Type[Foo])
25+
# assert_type(Foo, type[Foo])
2626

2727
f = Foo(attr="attr")
2828

29-
assert_type(dc.fields(f), Tuple[dc.Field[Any], ...])
30-
assert_type(dc.asdict(f), Dict[str, Any])
31-
assert_type(dc.astuple(f), Tuple[Any, ...])
29+
assert_type(dc.fields(f), tuple[dc.Field[Any], ...])
30+
assert_type(dc.asdict(f), dict[str, Any])
31+
assert_type(dc.astuple(f), tuple[Any, ...])
3232
assert_type(dc.replace(f, attr="new"), Foo)
3333

3434
if dc.is_dataclass(f):
@@ -39,17 +39,17 @@ class Foo:
3939

4040
def is_dataclass_any(arg: Any) -> None:
4141
if dc.is_dataclass(arg):
42-
assert_type(arg, Union["DataclassInstance", Type["DataclassInstance"]])
42+
assert_type(arg, DataclassInstance | type[DataclassInstance])
4343

4444

4545
def is_dataclass_object(arg: object) -> None:
4646
if dc.is_dataclass(arg):
47-
assert_type(arg, Union["DataclassInstance", Type["DataclassInstance"]])
47+
assert_type(arg, DataclassInstance | type[DataclassInstance])
4848

4949

5050
def is_dataclass_type(arg: type) -> None:
5151
if dc.is_dataclass(arg):
52-
assert_type(arg, Type["DataclassInstance"])
52+
assert_type(arg, type[DataclassInstance])
5353

5454

5555
def check_other_isdataclass_overloads(x: type, y: object) -> None:
@@ -68,26 +68,26 @@ def check_other_isdataclass_overloads(x: type, y: object) -> None:
6868
dc.replace(y) # type: ignore
6969

7070
if dc.is_dataclass(x):
71-
assert_type(x, Type["DataclassInstance"])
72-
assert_type(dc.fields(x), Tuple[dc.Field[Any], ...])
71+
assert_type(x, type[DataclassInstance])
72+
assert_type(dc.fields(x), tuple[dc.Field[Any], ...])
7373

7474
dc.asdict(x) # type: ignore
7575
dc.astuple(x) # type: ignore
7676
dc.replace(x) # type: ignore
7777

7878
if dc.is_dataclass(y):
79-
assert_type(y, Union["DataclassInstance", Type["DataclassInstance"]])
80-
assert_type(dc.fields(y), Tuple[dc.Field[Any], ...])
79+
assert_type(y, DataclassInstance | type[DataclassInstance])
80+
assert_type(dc.fields(y), tuple[dc.Field[Any], ...])
8181

8282
dc.asdict(y) # type: ignore
8383
dc.astuple(y) # type: ignore
8484
dc.replace(y) # type: ignore
8585

8686
if dc.is_dataclass(y) and not isinstance(y, type):
87-
assert_type(y, "DataclassInstance")
88-
assert_type(dc.fields(y), Tuple[dc.Field[Any], ...])
89-
assert_type(dc.asdict(y), Dict[str, Any])
90-
assert_type(dc.astuple(y), Tuple[Any, ...])
87+
assert_type(y, DataclassInstance)
88+
assert_type(dc.fields(y), tuple[dc.Field[Any], ...])
89+
assert_type(dc.asdict(y), dict[str, Any])
90+
assert_type(dc.astuple(y), tuple[Any, ...])
9191
dc.replace(y)
9292

9393

@@ -103,13 +103,13 @@ class _D: ...
103103

104104
# Regression test for #11653
105105
D = dc.make_dataclass(
106-
"D", [("a", Union[int, None]), "y", ("z", Annotated[FrozenSet[bytes], "metadata"], dc.field(default=frozenset({b"foo"})))]
106+
"D", [("a", int | None), "y", ("z", Annotated[frozenset[bytes], "metadata"], dc.field(default=frozenset({b"foo"})))]
107107
)
108108
# Check that it's inferred by the type checker as a class object of some kind
109109
# (but don't assert the exact type that `D` is inferred as,
110110
# in case a type checker decides to add some special-casing for
111111
# `make_dataclass` in the future)
112-
assert_type(D.__mro__, Tuple[type, ...])
112+
assert_type(D.__mro__, tuple[type, ...])
113113

114114

115115
if sys.version_info >= (3, 14):
@@ -148,6 +148,6 @@ def custom_dataclass(
148148

149149
dc.make_dataclass(
150150
"D",
151-
[("a", Union[int, None]), "y", ("z", Annotated[FrozenSet[bytes], "metadata"], dc.field(default=frozenset({b"foo"})))],
151+
[("a", int | None), "y", ("z", Annotated[frozenset[bytes], "metadata"], dc.field(default=frozenset({b"foo"})))],
152152
decorator=custom_dataclass,
153153
)

0 commit comments

Comments
 (0)