diff --git a/stdlib/@tests/test_cases/asyncio/check_gather.py b/stdlib/@tests/test_cases/asyncio/check_gather.py index 02a01e39731a..9649b63ef235 100644 --- a/stdlib/@tests/test_cases/asyncio/check_gather.py +++ b/stdlib/@tests/test_cases/asyncio/check_gather.py @@ -1,7 +1,7 @@ from __future__ import annotations import asyncio -from typing import Awaitable, List, Tuple, Union +from collections.abc import Awaitable from typing_extensions import assert_type @@ -15,20 +15,20 @@ async def coro2() -> str: async def test_gather(awaitable1: Awaitable[int], awaitable2: Awaitable[str]) -> None: a = await asyncio.gather(awaitable1) - assert_type(a, Tuple[int]) + assert_type(a, tuple[int]) b = await asyncio.gather(awaitable1, awaitable2, return_exceptions=True) - assert_type(b, Tuple[Union[int, BaseException], Union[str, BaseException]]) + assert_type(b, tuple[int | BaseException, str | BaseException]) c = await asyncio.gather(awaitable1, awaitable2, awaitable1, awaitable1, awaitable1, awaitable1) - assert_type(c, Tuple[int, str, int, int, int, int]) + assert_type(c, tuple[int, str, int, int, int, int]) d = await asyncio.gather(awaitable1, awaitable1, awaitable1, awaitable1, awaitable1, awaitable1, awaitable1) - assert_type(d, List[int]) + assert_type(d, list[int]) awaitables_list: list[Awaitable[int]] = [awaitable1] e = await asyncio.gather(*awaitables_list) - assert_type(e, List[int]) + assert_type(e, list[int]) # this case isn't reliable between typecheckers, no one would ever call it with no args anyway # f = await asyncio.gather() diff --git a/stdlib/@tests/test_cases/builtins/check_dict.py b/stdlib/@tests/test_cases/builtins/check_dict.py index fe74ad49408e..2b2fc5082933 100644 --- a/stdlib/@tests/test_cases/builtins/check_dict.py +++ b/stdlib/@tests/test_cases/builtins/check_dict.py @@ -1,7 +1,8 @@ from __future__ import annotations import os -from typing import Any, Dict, Generic, Iterable, Mapping, TypeVar, Union +from collections.abc import Iterable, Mapping +from typing import Any, Generic, TypeVar from typing_extensions import Self, assert_type ################################################################### @@ -15,9 +16,9 @@ # https://github.com/python/mypy/issues/12358 # bad = dict() good: dict[str, str] = dict() -assert_type(good, Dict[str, str]) +assert_type(good, dict[str, str]) -assert_type(dict(arg=1), Dict[str, int]) +assert_type(dict(arg=1), dict[str, int]) _KT = TypeVar("_KT") _VT = TypeVar("_VT") @@ -37,11 +38,11 @@ def __getitem__(self, __k: _KT) -> _VT: kt1: KeysAndGetItem[int, str] = KeysAndGetItem({0: ""}) -assert_type(dict(kt1), Dict[int, str]) +assert_type(dict(kt1), dict[int, str]) dict(kt1, arg="a") # type: ignore kt2: KeysAndGetItem[str, int] = KeysAndGetItem({"": 0}) -assert_type(dict(kt2, arg=1), Dict[str, int]) +assert_type(dict(kt2, arg=1), dict[str, int]) 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] dict(i1, arg="a") # type: ignore i2: Iterable[tuple[str, int]] = [("a", 1), ("b", 2)] -assert_type(dict(i2, arg=1), Dict[str, int]) +assert_type(dict(i2, arg=1), dict[str, int]) i3: Iterable[str] = ["a.b"] i4: Iterable[bytes] = [b"a.b"] -assert_type(dict(string.split(".") for string in i3), Dict[str, str]) -assert_type(dict(string.split(b".") for string in i4), Dict[bytes, bytes]) +assert_type(dict(string.split(".") for string in i3), dict[str, str]) +assert_type(dict(string.split(b".") for string in i4), dict[bytes, bytes]) dict(["foo", "bar", "baz"]) # type: ignore 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] int_value = 1 assert_type(d_any["key"], Any) -assert_type(d_any.get("key"), Union[Any, None]) -assert_type(d_any.get("key", None), Union[Any, None]) +assert_type(d_any.get("key"), Any | None) +assert_type(d_any.get("key", None), Any | None) assert_type(d_any.get("key", any_value), Any) assert_type(d_any.get("key", str_value), Any) assert_type(d_any.get("key", int_value), Any) assert_type(d_str["key"], str) -assert_type(d_str.get("key"), Union[str, None]) -assert_type(d_str.get("key", None), Union[str, None]) +assert_type(d_str.get("key"), str | None) +assert_type(d_str.get("key", None), str | None) # Pyright has str instead of Any here assert_type(d_str.get("key", any_value), Any) # pyright: ignore[reportAssertTypeFailure] assert_type(d_str.get("key", str_value), str) -assert_type(d_str.get("key", int_value), Union[str, int]) +assert_type(d_str.get("key", int_value), str | int) # Now with context! result: str @@ -184,7 +185,7 @@ def test_dict_dot_or( assert_type(a | b, dict[int, int]) assert_type(b | a, dict[int, int]) - assert_type(a | c, dict[Union[int, str], Union[int, str]]) + assert_type(a | c, dict[int | str, int | str]) # arbitrary mappings are not accepted by `dict.__or__`; # it has to be a subclass of `dict` @@ -192,8 +193,8 @@ def test_dict_dot_or( # but Mappings such as `os._Environ` or `CustomMappingWithDunderOr`, # which define `__ror__` methods that accept `dict`, are fine: - assert_type(a | os.environ, dict[Union[str, int], Union[str, int]]) - assert_type(os.environ | a, dict[Union[str, int], Union[str, int]]) + assert_type(a | os.environ, dict[int | str, int | str]) + assert_type(os.environ | a, dict[int | str, int | str]) assert_type(c | os.environ, dict[str, str]) assert_type(c | e, dict[str, str]) diff --git a/stdlib/@tests/test_cases/builtins/check_list.py b/stdlib/@tests/test_cases/builtins/check_list.py index 4113f5c66182..f284f2c55b23 100644 --- a/stdlib/@tests/test_cases/builtins/check_list.py +++ b/stdlib/@tests/test_cases/builtins/check_list.py @@ -1,6 +1,5 @@ from __future__ import annotations -from typing import List, Union from typing_extensions import assert_type @@ -16,6 +15,6 @@ def asd(self) -> int: combined = [Foo()] + [Bar()] -assert_type(combined, List[Union[Foo, Bar]]) +assert_type(combined, list[Foo | Bar]) for item in combined: assert_type(item.asd(), int) diff --git a/stdlib/@tests/test_cases/builtins/check_sum.py b/stdlib/@tests/test_cases/builtins/check_sum.py index ec9cd335c685..2a839abbd8f5 100644 --- a/stdlib/@tests/test_cases/builtins/check_sum.py +++ b/stdlib/@tests/test_cases/builtins/check_sum.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Any, List, Literal, Union +from typing import Any, Literal from typing_extensions import assert_type @@ -31,10 +31,10 @@ def __radd__(self, other: Any) -> Baz: assert_type(sum([True, False], True), int) assert_type(sum(literal_list), int) -assert_type(sum([["foo"], ["bar"]], ["baz"]), List[str]) +assert_type(sum([["foo"], ["bar"]], ["baz"]), list[str]) assert_type(sum([Foo(), Foo()], Foo()), Foo) -assert_type(sum([Baz(), Baz()]), Union[Baz, Literal[0]]) +assert_type(sum([Baz(), Baz()]), Baz | Literal[0]) # mypy and pyright infer the types differently for these, so we can't use assert_type # Just test that no error is emitted for any of these diff --git a/stdlib/@tests/test_cases/builtins/check_zip.py b/stdlib/@tests/test_cases/builtins/check_zip.py index fa6fcc7eae0f..c3b5997a3fd4 100644 --- a/stdlib/@tests/test_cases/builtins/check_zip.py +++ b/stdlib/@tests/test_cases/builtins/check_zip.py @@ -1,15 +1,15 @@ from __future__ import annotations -from typing import Sequence, Tuple +from collections.abc import Sequence from typing_extensions import assert_type ints: Sequence[int] = [1, 2, 3] strs: Sequence[str] = ["one", "two", "three"] floats: Sequence[float] = [1.0, 2.0, 3.0] -str_tuples: Sequence[Tuple[str]] = list((x,) for x in strs) +str_tuples: Sequence[tuple[str]] = list((x,) for x in strs) -assert_type(zip(ints), zip[Tuple[int]]) -assert_type(zip(ints, strs), zip[Tuple[int, str]]) -assert_type(zip(ints, strs, floats), zip[Tuple[int, str, float]]) -assert_type(zip(strs, ints, floats, ints), zip[Tuple[str, int, float, int]]) -assert_type(zip(strs, ints, floats, ints, str_tuples), zip[Tuple[str, int, float, int, Tuple[str]]]) +assert_type(zip(ints), zip[tuple[int]]) +assert_type(zip(ints, strs), zip[tuple[int, str]]) +assert_type(zip(ints, strs, floats), zip[tuple[int, str, float]]) +assert_type(zip(strs, ints, floats, ints), zip[tuple[str, int, float, int]]) +assert_type(zip(strs, ints, floats, ints, str_tuples), zip[tuple[str, int, float, int, tuple[str]]]) diff --git a/stdlib/@tests/test_cases/check_dataclasses.py b/stdlib/@tests/test_cases/check_dataclasses.py index 1594400e44fe..cb2a112dbb42 100644 --- a/stdlib/@tests/test_cases/check_dataclasses.py +++ b/stdlib/@tests/test_cases/check_dataclasses.py @@ -2,7 +2,7 @@ import dataclasses as dc import sys -from typing import TYPE_CHECKING, Any, Dict, FrozenSet, Tuple, Type, Union +from typing import TYPE_CHECKING, Any from typing_extensions import Annotated, assert_type if TYPE_CHECKING: @@ -14,7 +14,7 @@ class Foo: attr: str -assert_type(dc.fields(Foo), Tuple[dc.Field[Any], ...]) +assert_type(dc.fields(Foo), tuple[dc.Field[Any], ...]) dc.asdict(Foo) # type: ignore dc.astuple(Foo) # type: ignore @@ -22,13 +22,13 @@ class Foo: # See #9723 for why we can't make this assertion # if dc.is_dataclass(Foo): -# assert_type(Foo, Type[Foo]) +# assert_type(Foo, type[Foo]) f = Foo(attr="attr") -assert_type(dc.fields(f), Tuple[dc.Field[Any], ...]) -assert_type(dc.asdict(f), Dict[str, Any]) -assert_type(dc.astuple(f), Tuple[Any, ...]) +assert_type(dc.fields(f), tuple[dc.Field[Any], ...]) +assert_type(dc.asdict(f), dict[str, Any]) +assert_type(dc.astuple(f), tuple[Any, ...]) assert_type(dc.replace(f, attr="new"), Foo) if dc.is_dataclass(f): @@ -39,17 +39,17 @@ class Foo: def is_dataclass_any(arg: Any) -> None: if dc.is_dataclass(arg): - assert_type(arg, Union["DataclassInstance", Type["DataclassInstance"]]) + assert_type(arg, DataclassInstance | type[DataclassInstance]) def is_dataclass_object(arg: object) -> None: if dc.is_dataclass(arg): - assert_type(arg, Union["DataclassInstance", Type["DataclassInstance"]]) + assert_type(arg, DataclassInstance | type[DataclassInstance]) def is_dataclass_type(arg: type) -> None: if dc.is_dataclass(arg): - assert_type(arg, Type["DataclassInstance"]) + assert_type(arg, type[DataclassInstance]) def check_other_isdataclass_overloads(x: type, y: object) -> None: @@ -68,26 +68,26 @@ def check_other_isdataclass_overloads(x: type, y: object) -> None: dc.replace(y) # type: ignore if dc.is_dataclass(x): - assert_type(x, Type["DataclassInstance"]) - assert_type(dc.fields(x), Tuple[dc.Field[Any], ...]) + assert_type(x, type[DataclassInstance]) + assert_type(dc.fields(x), tuple[dc.Field[Any], ...]) dc.asdict(x) # type: ignore dc.astuple(x) # type: ignore dc.replace(x) # type: ignore if dc.is_dataclass(y): - assert_type(y, Union["DataclassInstance", Type["DataclassInstance"]]) - assert_type(dc.fields(y), Tuple[dc.Field[Any], ...]) + assert_type(y, DataclassInstance | type[DataclassInstance]) + assert_type(dc.fields(y), tuple[dc.Field[Any], ...]) dc.asdict(y) # type: ignore dc.astuple(y) # type: ignore dc.replace(y) # type: ignore if dc.is_dataclass(y) and not isinstance(y, type): - assert_type(y, "DataclassInstance") - assert_type(dc.fields(y), Tuple[dc.Field[Any], ...]) - assert_type(dc.asdict(y), Dict[str, Any]) - assert_type(dc.astuple(y), Tuple[Any, ...]) + assert_type(y, DataclassInstance) + assert_type(dc.fields(y), tuple[dc.Field[Any], ...]) + assert_type(dc.asdict(y), dict[str, Any]) + assert_type(dc.astuple(y), tuple[Any, ...]) dc.replace(y) @@ -103,13 +103,13 @@ class _D: ... # Regression test for #11653 D = dc.make_dataclass( - "D", [("a", Union[int, None]), "y", ("z", Annotated[FrozenSet[bytes], "metadata"], dc.field(default=frozenset({b"foo"})))] + "D", [("a", int | None), "y", ("z", Annotated[frozenset[bytes], "metadata"], dc.field(default=frozenset({b"foo"})))] ) # Check that it's inferred by the type checker as a class object of some kind # (but don't assert the exact type that `D` is inferred as, # in case a type checker decides to add some special-casing for # `make_dataclass` in the future) -assert_type(D.__mro__, Tuple[type, ...]) +assert_type(D.__mro__, tuple[type, ...]) if sys.version_info >= (3, 14): @@ -148,6 +148,6 @@ def custom_dataclass( dc.make_dataclass( "D", - [("a", Union[int, None]), "y", ("z", Annotated[FrozenSet[bytes], "metadata"], dc.field(default=frozenset({b"foo"})))], + [("a", int | None), "y", ("z", Annotated[frozenset[bytes], "metadata"], dc.field(default=frozenset({b"foo"})))], decorator=custom_dataclass, ) diff --git a/stdlib/@tests/test_cases/check_math.py b/stdlib/@tests/test_cases/check_math.py index d637c15ff178..5cba72589f42 100644 --- a/stdlib/@tests/test_cases/check_math.py +++ b/stdlib/@tests/test_cases/check_math.py @@ -3,7 +3,7 @@ from decimal import Decimal from fractions import Fraction from math import prod -from typing import Any, Literal, Union +from typing import Any, Literal from typing_extensions import assert_type @@ -35,16 +35,16 @@ def __rmul__(self, other: Any) -> SupportsMulAndRMul: assert_type(prod(literal_list), int) assert_type(prod([SupportsMul(), SupportsMul()], start=SupportsMul()), SupportsMul) -assert_type(prod([SupportsMulAndRMul(), SupportsMulAndRMul()]), Union[SupportsMulAndRMul, Literal[1]]) +assert_type(prod([SupportsMulAndRMul(), SupportsMulAndRMul()]), SupportsMulAndRMul | Literal[1]) -assert_type(prod([5.6, 3.2]), Union[float, Literal[1]]) -assert_type(prod([5.6, 3.2], start=3), Union[float, int]) +assert_type(prod([5.6, 3.2]), float | Literal[1]) +assert_type(prod([5.6, 3.2], start=3), float | int) -assert_type(prod([Fraction(7, 2), Fraction(3, 5)]), Union[Fraction, Literal[1]]) +assert_type(prod([Fraction(7, 2), Fraction(3, 5)]), Fraction | Literal[1]) assert_type(prod([Fraction(7, 2), Fraction(3, 5)], start=Fraction(1)), Fraction) -assert_type(prod([Decimal("3.14"), Decimal("2.71")]), Union[Decimal, Literal[1]]) +assert_type(prod([Decimal("3.14"), Decimal("2.71")]), Decimal | Literal[1]) assert_type(prod([Decimal("3.14"), Decimal("2.71")], start=Decimal("1.00")), Decimal) -assert_type(prod([complex(7, 2), complex(3, 5)]), Union[complex, Literal[1]]) +assert_type(prod([complex(7, 2), complex(3, 5)]), complex | Literal[1]) assert_type(prod([complex(7, 2), complex(3, 5)], start=complex(1, 0)), complex) diff --git a/stdlib/@tests/test_cases/check_os_path.py b/stdlib/@tests/test_cases/check_os_path.py index bd6911ed3cc9..dcaabca0b712 100644 --- a/stdlib/@tests/test_cases/check_os_path.py +++ b/stdlib/@tests/test_cases/check_os_path.py @@ -3,7 +3,7 @@ from _typeshed import StrOrBytesPath from os import PathLike from os.path import abspath, expanduser, expandvars -from typing import AnyStr, Union +from typing import AnyStr from typing_extensions import assert_type @@ -11,9 +11,9 @@ def test_str_path(str_path: StrOrBytesPath) -> None: # These methods are currently overloaded to work around python/mypy#17952 & python/mypy#11880 # Let's ensure that they'll still work with a StrOrBytesPath if the workaround is removed - assert_type(abspath(str_path), Union[str, bytes]) - assert_type(expanduser(str_path), Union[str, bytes]) - assert_type(expandvars(str_path), Union[str, bytes]) + assert_type(abspath(str_path), str | bytes) + assert_type(expanduser(str_path), str | bytes) + assert_type(expandvars(str_path), str | bytes) # See python/mypy#17952 diff --git a/stdlib/@tests/test_cases/check_tkinter.py b/stdlib/@tests/test_cases/check_tkinter.py index acb9a24ec5b1..62ba0d11f045 100644 --- a/stdlib/@tests/test_cases/check_tkinter.py +++ b/stdlib/@tests/test_cases/check_tkinter.py @@ -4,7 +4,6 @@ import tkinter import traceback import types -from typing import Optional, Tuple from typing_extensions import assert_type @@ -36,22 +35,22 @@ def foo(x: int, y: str) -> None: t = tkinter.Text() t.insert("end", "asd asd asd\nasd asd") -assert_type(t.count("1.0", "2.3"), Optional[Tuple[int]]) # (15,) -assert_type(t.count("2.3", "2.3"), Optional[Tuple[int]]) # None -assert_type(t.count("1.0", "2.3", "indices"), Optional[Tuple[int]]) # (15,) -assert_type(t.count("2.3", "2.3", "indices"), Optional[Tuple[int]]) # None -assert_type(t.count("1.0", "2.3", "indices", "update"), Optional[int]) # 15 -assert_type(t.count("2.3", "2.3", "indices", "update"), Optional[int]) # None -assert_type(t.count("1.0", "2.3", "indices", "lines"), Tuple[int, int]) # (15, 1) -assert_type(t.count("2.3", "2.3", "indices", "lines"), Tuple[int, int]) # (0, 0) -assert_type(t.count("1.0", "2.3", "indices", "lines", "update"), Tuple[int, ...]) # (15, 1) -assert_type(t.count("2.3", "2.3", "indices", "lines", "update"), Tuple[int, ...]) # (0, 0) -assert_type(t.count("1.0", "2.3", "indices", "lines", "chars"), Tuple[int, ...]) # (15, 1, 15) -assert_type(t.count("2.3", "2.3", "indices", "lines", "chars"), Tuple[int, ...]) # (0, 0, 0) -assert_type(t.count("1.0", "2.3", "indices", "lines", "chars", "update"), Tuple[int, ...]) # (15, 1, 15) -assert_type(t.count("2.3", "2.3", "indices", "lines", "chars", "update"), Tuple[int, ...]) # (0, 0, 0) -assert_type(t.count("1.0", "2.3", "indices", "lines", "chars", "ypixels"), Tuple[int, ...]) # (15, 1, 15, 19) -assert_type(t.count("2.3", "2.3", "indices", "lines", "chars", "ypixels"), Tuple[int, ...]) # (0, 0, 0, 0) +assert_type(t.count("1.0", "2.3"), tuple[int] | None) # (15,) +assert_type(t.count("2.3", "2.3"), tuple[int] | None) # None +assert_type(t.count("1.0", "2.3", "indices"), tuple[int] | None) # (15,) +assert_type(t.count("2.3", "2.3", "indices"), tuple[int] | None) # None +assert_type(t.count("1.0", "2.3", "indices", "update"), int | None) # 15 +assert_type(t.count("2.3", "2.3", "indices", "update"), int | None) # None +assert_type(t.count("1.0", "2.3", "indices", "lines"), tuple[int, int]) # (15, 1) +assert_type(t.count("2.3", "2.3", "indices", "lines"), tuple[int, int]) # (0, 0) +assert_type(t.count("1.0", "2.3", "indices", "lines", "update"), tuple[int, ...]) # (15, 1) +assert_type(t.count("2.3", "2.3", "indices", "lines", "update"), tuple[int, ...]) # (0, 0) +assert_type(t.count("1.0", "2.3", "indices", "lines", "chars"), tuple[int, ...]) # (15, 1, 15) +assert_type(t.count("2.3", "2.3", "indices", "lines", "chars"), tuple[int, ...]) # (0, 0, 0)—— +assert_type(t.count("1.0", "2.3", "indices", "lines", "chars", "update"), tuple[int, ...]) # (15, 1, 15) +assert_type(t.count("2.3", "2.3", "indices", "lines", "chars", "update"), tuple[int, ...]) # (0, 0, 0) +assert_type(t.count("1.0", "2.3", "indices", "lines", "chars", "ypixels"), tuple[int, ...]) # (15, 1, 15, 19) +assert_type(t.count("2.3", "2.3", "indices", "lines", "chars", "ypixels"), tuple[int, ...]) # (0, 0, 0, 0) if sys.version_info >= (3, 13): assert_type(t.count("1.0", "2.3", return_ints=True), int) # 15 @@ -60,15 +59,15 @@ def foo(x: int, y: str) -> None: assert_type(t.count("2.3", "2.3", "indices", return_ints=True), int) # 0 assert_type(t.count("1.0", "2.3", "indices", "update", return_ints=True), int) # 15 assert_type(t.count("2.3", "2.3", "indices", "update", return_ints=True), int) # 0 - assert_type(t.count("1.0", "2.3", "indices", "lines", return_ints=True), Tuple[int, int]) # (15, 1) - assert_type(t.count("2.3", "2.3", "indices", "lines", return_ints=True), Tuple[int, int]) # (0, 0) - assert_type(t.count("1.0", "2.3", "indices", "lines", "update", return_ints=True), Tuple[int, ...]) # (15, 1) - assert_type(t.count("2.3", "2.3", "indices", "lines", "update", return_ints=True), Tuple[int, ...]) # (0, 0) - assert_type(t.count("1.0", "2.3", "indices", "lines", "chars", return_ints=True), Tuple[int, ...]) # (15, 1, 15) - assert_type(t.count("2.3", "2.3", "indices", "lines", "chars", return_ints=True), Tuple[int, ...]) # (0, 0, 0) - assert_type(t.count("1.0", "2.3", "indices", "lines", "chars", "update", return_ints=True), Tuple[int, ...]) # (15, 1, 15) - assert_type(t.count("2.3", "2.3", "indices", "lines", "chars", "update", return_ints=True), Tuple[int, ...]) # (0, 0, 0) + assert_type(t.count("1.0", "2.3", "indices", "lines", return_ints=True), tuple[int, int]) # (15, 1) + assert_type(t.count("2.3", "2.3", "indices", "lines", return_ints=True), tuple[int, int]) # (0, 0) + assert_type(t.count("1.0", "2.3", "indices", "lines", "update", return_ints=True), tuple[int, ...]) # (15, 1) + assert_type(t.count("2.3", "2.3", "indices", "lines", "update", return_ints=True), tuple[int, ...]) # (0, 0) + assert_type(t.count("1.0", "2.3", "indices", "lines", "chars", return_ints=True), tuple[int, ...]) # (15, 1, 15) + assert_type(t.count("2.3", "2.3", "indices", "lines", "chars", return_ints=True), tuple[int, ...]) # (0, 0, 0) + assert_type(t.count("1.0", "2.3", "indices", "lines", "chars", "update", return_ints=True), tuple[int, ...]) # (15, 1, 15) + assert_type(t.count("2.3", "2.3", "indices", "lines", "chars", "update", return_ints=True), tuple[int, ...]) # (0, 0, 0) assert_type( - t.count("1.0", "2.3", "indices", "lines", "chars", "ypixels", return_ints=True), Tuple[int, ...] + t.count("1.0", "2.3", "indices", "lines", "chars", "ypixels", return_ints=True), tuple[int, ...] ) # (15, 1, 15, 19) - assert_type(t.count("2.3", "2.3", "indices", "lines", "chars", "ypixels", return_ints=True), Tuple[int, ...]) # (0, 0, 0, 0) + assert_type(t.count("2.3", "2.3", "indices", "lines", "chars", "ypixels", return_ints=True), tuple[int, ...]) # (0, 0, 0, 0) diff --git a/stdlib/@tests/test_cases/check_types.py b/stdlib/@tests/test_cases/check_types.py index 83040989f31f..a9c2eeddbfdf 100644 --- a/stdlib/@tests/test_cases/check_types.py +++ b/stdlib/@tests/test_cases/check_types.py @@ -3,7 +3,7 @@ import sys import types from collections import UserDict -from typing import Any, Literal, TypeVar, Union +from typing import Any, Literal, TypeVar from typing_extensions import assert_type _T = TypeVar("_T") @@ -36,11 +36,11 @@ mp = types.MappingProxyType({1: 2, 3: 4}) mp.get("x") # type: ignore item = mp.get(1) -assert_type(item, Union[int, None]) +assert_type(item, int | None) item_2 = mp.get(2, 0) assert_type(item_2, int) item_3 = mp.get(3, "default") -assert_type(item_3, Union[int, str]) +assert_type(item_3, int | str) # Default isn't accepted as a keyword argument. mp.get(4, default="default") # type: ignore diff --git a/stdlib/@tests/test_cases/check_unittest.py b/stdlib/@tests/test_cases/check_unittest.py index bbc2a2ba4843..75bf0a0e3353 100644 --- a/stdlib/@tests/test_cases/check_unittest.py +++ b/stdlib/@tests/test_cases/check_unittest.py @@ -5,7 +5,7 @@ from datetime import datetime, timedelta from decimal import Decimal from fractions import Fraction -from typing import TypedDict, Union +from typing import TypedDict from typing_extensions import assert_type from unittest.mock import _ANY, ANY, AsyncMock, MagicMock, Mock, patch @@ -181,7 +181,7 @@ def method() -> int: with patch("sys.exit") as default_new_enter: - assert_type(default_new_enter, Union[MagicMock, AsyncMock]) + assert_type(default_new_enter, MagicMock | AsyncMock) with patch("sys.exit", new=42) as explicit_new_enter: assert_type(explicit_new_enter, int) @@ -219,7 +219,7 @@ def obj_f_explicit_new_callable(i: int, new_callable_ret: int) -> str: with patch.object(Decimal, "exp") as obj_default_new_enter: - assert_type(obj_default_new_enter, Union[MagicMock, AsyncMock]) + assert_type(obj_default_new_enter, MagicMock | AsyncMock) with patch.object(Decimal, "exp", new=42) as obj_explicit_new_enter: assert_type(obj_explicit_new_enter, int) diff --git a/stdlib/@tests/test_cases/collections/check_defaultdict.py b/stdlib/@tests/test_cases/collections/check_defaultdict.py index f608f3f3062e..f29aa8778a3d 100644 --- a/stdlib/@tests/test_cases/collections/check_defaultdict.py +++ b/stdlib/@tests/test_cases/collections/check_defaultdict.py @@ -6,7 +6,8 @@ import os from collections import defaultdict -from typing import Mapping, TypeVar, Union +from collections.abc import Mapping +from typing import TypeVar from typing_extensions import Self, assert_type _KT = TypeVar("_KT") @@ -40,7 +41,7 @@ def test_defaultdict_dot_or( # In contrast to `dict.__or__`, `defaultdict.__or__` returns `Self` if called on a subclass of `defaultdict`: assert_type(b | a, CustomDefaultDictSubclass[int, int]) - assert_type(a | c, defaultdict[Union[int, str], Union[int, str]]) + assert_type(a | c, defaultdict[int | str, int | str]) # arbitrary mappings are not accepted by `defaultdict.__or__`; # it has to be a subclass of `dict` @@ -49,8 +50,8 @@ def test_defaultdict_dot_or( # but Mappings such as `os._Environ` or `CustomMappingWithDunderOr`, # which define `__ror__` methods that accept `dict`, are fine # (`os._Environ.__(r)or__` always returns `dict`, even if a `defaultdict` is passed): - assert_type(a | os.environ, dict[Union[str, int], Union[str, int]]) - assert_type(os.environ | a, dict[Union[str, int], Union[str, int]]) + assert_type(a | os.environ, dict[int | str, int | str]) + assert_type(os.environ | a, dict[int | str, int | str]) assert_type(c | os.environ, dict[str, str]) assert_type(c | e, dict[str, str]) diff --git a/stdlib/@tests/test_cases/typing/check_MutableMapping.py b/stdlib/@tests/test_cases/typing/check_MutableMapping.py index 1e9d747fc8f6..776e12018e0f 100644 --- a/stdlib/@tests/test_cases/typing/check_MutableMapping.py +++ b/stdlib/@tests/test_cases/typing/check_MutableMapping.py @@ -1,6 +1,7 @@ from __future__ import annotations -from typing import Any, Hashable, Sequence, Union +from collections.abc import Hashable, Sequence +from typing import Any from typing_extensions import assert_type @@ -46,8 +47,8 @@ def check_setdefault_method() -> None: d.setdefault(1) # type: ignore assert_type(d.setdefault(1, "x"), str) - assert_type(d2.setdefault(1), Union[str, None]) - assert_type(d2.setdefault(1, None), Union[str, None]) - assert_type(d2.setdefault(1, "x"), Union[str, None]) - assert_type(d3.setdefault(1), Union[Any, None]) + assert_type(d2.setdefault(1), str | None) + assert_type(d2.setdefault(1, None), str | None) + assert_type(d2.setdefault(1, "x"), str | None) + assert_type(d3.setdefault(1), Any | None) assert_type(d3.setdefault(1, "x"), Any) diff --git a/stubs/WebOb/@tests/test_cases/check_cachecontrol.py b/stubs/WebOb/@tests/test_cases/check_cachecontrol.py index dd20460e466a..d011b01c9586 100644 --- a/stubs/WebOb/@tests/test_cases/check_cachecontrol.py +++ b/stubs/WebOb/@tests/test_cases/check_cachecontrol.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Any, Literal, Union +from typing import Any, Literal from typing_extensions import assert_type from webob.cachecontrol import CacheControl @@ -24,15 +24,15 @@ assert_type(shared_cc, CacheControl[None]) any_cc = CacheControl[Any]({}, None) -assert_type(req_cc.max_stale, Union[int, Literal["*"], None]) +assert_type(req_cc.max_stale, int | Literal["*"] | None) res_cc.max_stale # type: ignore shared_cc.max_stale # type: ignore -assert_type(any_cc.max_stale, Union[int, Literal["*"], None]) +assert_type(any_cc.max_stale, int | Literal["*"] | None) -assert_type(req_cc.min_fresh, Union[int, None]) +assert_type(req_cc.min_fresh, int | None) res_cc.min_fresh # type: ignore shared_cc.min_fresh # type: ignore -assert_type(any_cc.min_fresh, Union[int, None]) +assert_type(any_cc.min_fresh, int | None) assert_type(req_cc.only_if_cached, bool) res_cc.only_if_cached # type: ignore @@ -46,14 +46,14 @@ # NOTE: pyright gets confused about the `Literal["*"]` the types match req_cc.private # type: ignore -assert_type(res_cc.private, Union[str, Literal["*"], None]) # pyright: ignore +assert_type(res_cc.private, str | Literal["*"] | None) # pyright: ignore shared_cc.private # type: ignore -assert_type(any_cc.private, Union[str, Literal["*"], None]) # pyright: ignore +assert_type(any_cc.private, str | Literal["*"] | None) # pyright: ignore -assert_type(req_cc.no_cache, Union[str, Literal["*"], None]) # pyright: ignore -assert_type(res_cc.no_cache, Union[str, Literal["*"], None]) # pyright: ignore -assert_type(shared_cc.no_cache, Union[str, Literal["*"], None]) # pyright: ignore -assert_type(any_cc.no_cache, Union[str, Literal["*"], None]) # pyright: ignore +assert_type(req_cc.no_cache, str | Literal["*"] | None) # pyright: ignore +assert_type(res_cc.no_cache, str | Literal["*"] | None) # pyright: ignore +assert_type(shared_cc.no_cache, str | Literal["*"] | None) # pyright: ignore +assert_type(any_cc.no_cache, str | Literal["*"] | None) # pyright: ignore assert_type(req_cc.no_store, bool) assert_type(res_cc.no_store, bool) @@ -76,27 +76,27 @@ assert_type(any_cc.proxy_revalidate, bool) # NOTE: pyright gets confused about the `Literal[-1]` the types match -assert_type(req_cc.max_age, Union[int, Literal[-1], None]) # pyright: ignore -assert_type(res_cc.max_age, Union[int, Literal[-1], None]) # pyright: ignore -assert_type(shared_cc.max_age, Union[int, Literal[-1], None]) # pyright: ignore -assert_type(any_cc.max_age, Union[int, Literal[-1], None]) # pyright: ignore +assert_type(req_cc.max_age, int | Literal[-1] | None) # pyright: ignore +assert_type(res_cc.max_age, int | Literal[-1] | None) # pyright: ignore +assert_type(shared_cc.max_age, int | Literal[-1] | None) # pyright: ignore +assert_type(any_cc.max_age, int | Literal[-1] | None) # pyright: ignore req_cc.s_maxage # type: ignore -assert_type(res_cc.s_maxage, Union[int, None]) +assert_type(res_cc.s_maxage, int | None) shared_cc.s_maxage # type: ignore -assert_type(any_cc.s_maxage, Union[int, None]) +assert_type(any_cc.s_maxage, int | None) req_cc.s_max_age # type: ignore -assert_type(res_cc.s_max_age, Union[int, None]) +assert_type(res_cc.s_max_age, int | None) shared_cc.s_max_age # type: ignore -assert_type(any_cc.s_max_age, Union[int, None]) +assert_type(any_cc.s_max_age, int | None) req_cc.stale_while_revalidate # type: ignore -assert_type(res_cc.stale_while_revalidate, Union[int, None]) +assert_type(res_cc.stale_while_revalidate, int | None) shared_cc.stale_while_revalidate # type: ignore -assert_type(any_cc.stale_while_revalidate, Union[int, None]) +assert_type(any_cc.stale_while_revalidate, int | None) req_cc.stale_if_error # type: ignore -assert_type(res_cc.stale_if_error, Union[int, None]) +assert_type(res_cc.stale_if_error, int | None) shared_cc.stale_if_error # type: ignore -assert_type(any_cc.stale_if_error, Union[int, None]) +assert_type(any_cc.stale_if_error, int | None) diff --git a/stubs/openpyxl/@tests/test_cases/check_base_descriptors.py b/stubs/openpyxl/@tests/test_cases/check_base_descriptors.py index 858892a974bc..f200aaf6debc 100644 --- a/stubs/openpyxl/@tests/test_cases/check_base_descriptors.py +++ b/stubs/openpyxl/@tests/test_cases/check_base_descriptors.py @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer from datetime import date, datetime, time -from typing import Any, List, Literal, Tuple, Union +from typing import Any, Literal from typing_extensions import assert_type from openpyxl.descriptors import Strict @@ -40,8 +40,8 @@ class WithDescriptors(Serialisable): noneset_tuple = NoneSet(values=("a", 1, 0.0)) noneset_list = NoneSet(values=["a", 1, 0.0]) - length_tuple = Length[Tuple[str, str]](length=1) # Can't validate tuple length in a generic manner - length_list = Length[List[str]](length=1) + length_tuple = Length[tuple[str, str]](length=1) # Can't validate tuple length in a generic manner + length_list = Length[list[str]](length=1) length_invalid = Length[object](length=1) # type: ignore match_pattern_str_default = MatchPattern(pattern="") @@ -89,15 +89,15 @@ class WithDescriptors(Serialisable): assert_type(typed_not_none, Typed[str, Literal[False]]) assert_type(typed_none, Typed[str, Literal[True]]) - assert_type(set_tuple, Set[Union[Literal["a", 1], float]]) # type: ignore[assert-type] # False-positive in mypy - assert_type(set_list, Set[Union[str, int, float]]) # type: ignore[assert-type] # False-positive in mypy # Literals are simplified in non-tuples - assert_type(set_tuple_none, Set[Union[Literal["a", 1, None], float]]) # type: ignore[assert-type] # False-positive in mypy + assert_type(set_tuple, Set[Literal["a", 1] | float]) # type: ignore[assert-type] # False-positive in mypy + assert_type(set_list, Set[str | int | float]) # type: ignore[assert-type] # False-positive in mypy # Literals are simplified in non-tuples + assert_type(set_tuple_none, Set[Literal["a", 1, None] | float]) # type: ignore[assert-type] # False-positive in mypy - assert_type(noneset_tuple, NoneSet[Union[Literal["a", 1], float]]) # type: ignore[assert-type] # False-positive in mypy - assert_type(noneset_list, NoneSet[Union[str, float]]) # type: ignore[assert-type] # False-positive in mypy# int and float are merged in generic unions + assert_type(noneset_tuple, NoneSet[Literal["a", 1] | float]) # type: ignore[assert-type] # False-positive in mypy + assert_type(noneset_list, NoneSet[str | float]) # type: ignore[assert-type] # False-positive in mypy# int and float are merged in generic unions - assert_type(length_tuple, Length[Tuple[str, str]]) - assert_type(length_list, Length[List[str]]) + assert_type(length_tuple, Length[tuple[str, str]]) + assert_type(length_list, Length[list[str]]) assert_type(match_pattern_str_default, MatchPattern[str, Literal[False]]) assert_type(match_pattern_str, MatchPattern[str, Literal[False]]) @@ -160,45 +160,45 @@ class WithDescriptorsStrict(Strict): assert_type(with_descriptors.descriptor, str) assert_type(with_descriptors.typed_not_none, str) -assert_type(with_descriptors.typed_none, Union[str, None]) +assert_type(with_descriptors.typed_none, str | None) -assert_type(with_descriptors.set_tuple, Union[Literal["a", 1], float]) # type: ignore[assert-type] # False-positive in mypy -assert_type(with_descriptors.set_list, Union[str, int, float]) # type: ignore[assert-type] # False-positive in mypy # Literals are simplified in non-tuples -assert_type(with_descriptors.set_tuple_none, Union[Literal["a", 1, None], float]) # type: ignore[assert-type] # False-positive in mypy +assert_type(with_descriptors.set_tuple, Literal["a", 1] | float) # type: ignore[assert-type] # False-positive in mypy +assert_type(with_descriptors.set_list, str | int | float) # type: ignore[assert-type] # False-positive in mypy # Literals are simplified in non-tuples +assert_type(with_descriptors.set_tuple_none, Literal["a", 1, None] | float) # type: ignore[assert-type] # False-positive in mypy -assert_type(with_descriptors.noneset_tuple, Union[Literal["a", 1], float, None]) # type: ignore[assert-type] # False-positive in mypy -assert_type(with_descriptors.noneset_list, Union[str, float, None]) # type: ignore[assert-type] # False-positive in mypy # int and float are merged in generic unions +assert_type(with_descriptors.noneset_tuple, Literal["a", 1] | float | None) # type: ignore[assert-type] # False-positive in mypy +assert_type(with_descriptors.noneset_list, str | float | None) # type: ignore[assert-type] # False-positive in mypy # int and float are merged in generic unions -assert_type(with_descriptors.length_tuple, Tuple[str, str]) -assert_type(with_descriptors.length_list, List[str]) +assert_type(with_descriptors.length_tuple, tuple[str, str]) +assert_type(with_descriptors.length_list, list[str]) assert_type(with_descriptors.match_pattern_str, str) -assert_type(with_descriptors.match_pattern_str_none, Union[str, None]) +assert_type(with_descriptors.match_pattern_str_none, str | None) assert_type(with_descriptors.match_pattern_bytes, ReadableBuffer) -assert_type(with_descriptors.match_pattern_bytes_none, Union[ReadableBuffer, None]) +assert_type(with_descriptors.match_pattern_bytes_none, ReadableBuffer | None) assert_type(with_descriptors.convertible_not_none, int) -assert_type(with_descriptors.convertible_none, Union[int, None]) +assert_type(with_descriptors.convertible_none, int | None) assert_type(with_descriptors.minmax_float, float) -assert_type(with_descriptors.minmax_float_none, Union[float, None]) +assert_type(with_descriptors.minmax_float_none, float | None) assert_type(with_descriptors.minmax_int, int) -assert_type(with_descriptors.minmax_int_none, Union[int, None]) +assert_type(with_descriptors.minmax_int_none, int | None) assert_type(with_descriptors.bool_not_none, bool) -assert_type(with_descriptors.bool_none, Union[bool, None]) +assert_type(with_descriptors.bool_none, bool | None) assert_type(with_descriptors.datetime_not_none, datetime) -assert_type(with_descriptors.datetime_none, Union[datetime, None]) +assert_type(with_descriptors.datetime_none, datetime | None) assert_type(with_descriptors.string_not_none, str) -assert_type(with_descriptors.string_none, Union[str, None]) +assert_type(with_descriptors.string_none, str | None) assert_type(with_descriptors.float_not_none, float) -assert_type(with_descriptors.float_none, Union[float, None]) +assert_type(with_descriptors.float_none, float | None) assert_type(with_descriptors.integer_not_none, int) -assert_type(with_descriptors.integer_none, Union[int, None]) +assert_type(with_descriptors.integer_none, int | None) # Test setters (expected type, None, unexpected type) diff --git a/stubs/openpyxl/@tests/test_cases/check_nested_descriptors.py b/stubs/openpyxl/@tests/test_cases/check_nested_descriptors.py index 3d36ab215fff..ceb0a1c485d5 100644 --- a/stubs/openpyxl/@tests/test_cases/check_nested_descriptors.py +++ b/stubs/openpyxl/@tests/test_cases/check_nested_descriptors.py @@ -4,7 +4,7 @@ # These tests are essentially a mirror of check_base_descriptors from __future__ import annotations -from typing import Literal, Union, cast +from typing import Literal, cast from typing_extensions import assert_type from openpyxl.descriptors import Strict @@ -81,12 +81,12 @@ class WithDescriptors(Serialisable): # Test inferred annotation assert_type(descriptor, Nested[str]) - assert_type(set_tuple, NestedSet[Union[Literal["a", 1], float]]) # type: ignore[assert-type] # False-positive in mypy - assert_type(set_list, NestedSet[Union[str, int, float]]) # type: ignore[assert-type] # False-positive in mypy # Literals are simplified in non-tuples - assert_type(set_tuple_none, NestedSet[Union[Literal["a", 1, None], float]]) # type: ignore[assert-type] # False-positive in mypy + assert_type(set_tuple, NestedSet[Literal["a", 1] | float]) # type: ignore[assert-type] # False-positive in mypy + assert_type(set_list, NestedSet[str | int | float]) # type: ignore[assert-type] # False-positive in mypy # Literals are simplified in non-tuples + assert_type(set_tuple_none, NestedSet[Literal["a", 1, None] | float]) # type: ignore[assert-type] # False-positive in mypy - assert_type(noneset_tuple, NestedNoneSet[Union[Literal["a", 1], float]]) # type: ignore[assert-type] # False-positive in mypy - assert_type(noneset_list, NestedNoneSet[Union[str, float]]) # type: ignore[assert-type] # False-positive in mypy# int and float are merged in generic unions + assert_type(noneset_tuple, NestedNoneSet[Literal["a", 1] | float]) # type: ignore[assert-type] # False-positive in mypy + assert_type(noneset_list, NestedNoneSet[str | float]) # type: ignore[assert-type] # False-positive in mypy# int and float are merged in generic unions assert_type(convertible_default, NestedValue[int, Literal[False]]) assert_type(convertible_not_none, NestedValue[int, Literal[False]]) @@ -147,40 +147,40 @@ class WithDescriptorsStrict(Strict): # Test getters assert_type(with_descriptors.descriptor, str) -assert_type(with_descriptors.set_tuple, Union[Literal["a", 1], float]) # type: ignore[assert-type] # False-positive in mypy -assert_type(with_descriptors.set_list, Union[str, int, float]) # type: ignore[assert-type] # False-positive in mypy # Literals are simplified in non-tuples -assert_type(with_descriptors.set_tuple_none, Union[Literal["a", 1, None], float]) # type: ignore[assert-type] # False-positive in mypy +assert_type(with_descriptors.set_tuple, Literal["a", 1] | float) # type: ignore[assert-type] # False-positive in mypy +assert_type(with_descriptors.set_list, str | int | float) # type: ignore[assert-type] # False-positive in mypy # Literals are simplified in non-tuples +assert_type(with_descriptors.set_tuple_none, Literal["a", 1, None] | float) # type: ignore[assert-type] # False-positive in mypy -assert_type(with_descriptors.noneset_tuple, Union[Literal["a", 1], float, None]) # type: ignore[assert-type] # False-positive in mypy -assert_type(with_descriptors.noneset_list, Union[str, float, None]) # type: ignore[assert-type] # False-positive in mypy # int and float are merged in generic unions +assert_type(with_descriptors.noneset_tuple, Literal["a", 1] | float | None) # type: ignore[assert-type] # False-positive in mypy +assert_type(with_descriptors.noneset_list, str | float | None) # type: ignore[assert-type] # False-positive in mypy # int and float are merged in generic unions assert_type(with_descriptors.convertible_not_none, int) -assert_type(with_descriptors.convertible_none, Union[int, None]) +assert_type(with_descriptors.convertible_none, int | None) assert_type(with_descriptors.text_str_not_none, str) -assert_type(with_descriptors.text_str_none, Union[str, None]) +assert_type(with_descriptors.text_str_none, str | None) assert_type(with_descriptors.text_int_not_none, int) -assert_type(with_descriptors.text_int_none, Union[int, None]) +assert_type(with_descriptors.text_int_none, int | None) assert_type(with_descriptors.minmax_float, float) -assert_type(with_descriptors.minmax_float_none, Union[float, None]) +assert_type(with_descriptors.minmax_float_none, float | None) assert_type(with_descriptors.minmax_int, int) -assert_type(with_descriptors.minmax_int_none, Union[int, None]) +assert_type(with_descriptors.minmax_int_none, int | None) assert_type(with_descriptors.bool_not_none, bool) -assert_type(with_descriptors.bool_none, Union[bool, None]) +assert_type(with_descriptors.bool_none, bool | None) assert_type(with_descriptors.emptytag_not_none, bool) -assert_type(with_descriptors.emptytag_none, Union[bool, None]) +assert_type(with_descriptors.emptytag_none, bool | None) assert_type(with_descriptors.string_not_none, str) -assert_type(with_descriptors.string_none, Union[str, None]) +assert_type(with_descriptors.string_none, str | None) assert_type(with_descriptors.float_not_none, float) -assert_type(with_descriptors.float_none, Union[float, None]) +assert_type(with_descriptors.float_none, float | None) assert_type(with_descriptors.integer_not_none, int) -assert_type(with_descriptors.integer_none, Union[int, None]) +assert_type(with_descriptors.integer_none, int | None) # Test setters (expected type, None, unexpected type, Elements) diff --git a/stubs/pyxdg/@tests/test_cases/check_IniFile.py b/stubs/pyxdg/@tests/test_cases/check_IniFile.py index d73d09a04dc1..2ca08cf09d36 100644 --- a/stubs/pyxdg/@tests/test_cases/check_IniFile.py +++ b/stubs/pyxdg/@tests/test_cases/check_IniFile.py @@ -1,7 +1,6 @@ from __future__ import annotations import re -from typing import List, Tuple from typing_extensions import assert_type from xdg.IniFile import IniFile @@ -57,36 +56,36 @@ assert_type(IniFile().get("some_key", strict=True, list=False, type="string"), str) assert_type(IniFile().get("some_key", group="group", locale=True, strict=True, list=False, type="string"), str) -# Get List[str] -assert_type(IniFile().get("some_key", "group", True, "string", True), List[str]) -assert_type(IniFile().get("some_key", "group", True, "string", True, False), List[str]) -assert_type(IniFile().get("some_key", "group", True, "string", True, True), List[str]) +# Get list[str] +assert_type(IniFile().get("some_key", "group", True, "string", True), list[str]) +assert_type(IniFile().get("some_key", "group", True, "string", True, False), list[str]) +assert_type(IniFile().get("some_key", "group", True, "string", True, True), list[str]) # Keyword parameters -assert_type(IniFile().get("some_key", list=True, group=None), List[str]) -assert_type(IniFile().get("some_key", list=True, group="group"), List[str]) -assert_type(IniFile().get("some_key", list=True, locale=False), List[str]) -assert_type(IniFile().get("some_key", list=True, locale=True), List[str]) -assert_type(IniFile().get("some_key", list=True, strict=False), List[str]) -assert_type(IniFile().get("some_key", list=True, strict=True), List[str]) -assert_type(IniFile().get("some_key", list=True, group="group", locale=True, strict=True), List[str]) +assert_type(IniFile().get("some_key", list=True, group=None), list[str]) +assert_type(IniFile().get("some_key", list=True, group="group"), list[str]) +assert_type(IniFile().get("some_key", list=True, locale=False), list[str]) +assert_type(IniFile().get("some_key", list=True, locale=True), list[str]) +assert_type(IniFile().get("some_key", list=True, strict=False), list[str]) +assert_type(IniFile().get("some_key", list=True, strict=True), list[str]) +assert_type(IniFile().get("some_key", list=True, group="group", locale=True, strict=True), list[str]) # Explicitly set list -assert_type(IniFile().get("some_key", list=True), List[str]) -assert_type(IniFile().get("some_key", group=None, list=True), List[str]) -assert_type(IniFile().get("some_key", group="group", list=True), List[str]) -assert_type(IniFile().get("some_key", locale=False, list=True), List[str]) -assert_type(IniFile().get("some_key", locale=True, list=True), List[str]) -assert_type(IniFile().get("some_key", strict=False, list=True), List[str]) -assert_type(IniFile().get("some_key", strict=True, list=True), List[str]) -assert_type(IniFile().get("some_key", group="group", locale=True, strict=True, list=True), List[str]) +assert_type(IniFile().get("some_key", list=True), list[str]) +assert_type(IniFile().get("some_key", group=None, list=True), list[str]) +assert_type(IniFile().get("some_key", group="group", list=True), list[str]) +assert_type(IniFile().get("some_key", locale=False, list=True), list[str]) +assert_type(IniFile().get("some_key", locale=True, list=True), list[str]) +assert_type(IniFile().get("some_key", strict=False, list=True), list[str]) +assert_type(IniFile().get("some_key", strict=True, list=True), list[str]) +assert_type(IniFile().get("some_key", group="group", locale=True, strict=True, list=True), list[str]) # Explicitly set both -assert_type(IniFile().get("some_key", list=True, type="string"), List[str]) -assert_type(IniFile().get("some_key", group=None, list=True, type="string"), List[str]) -assert_type(IniFile().get("some_key", group="group", list=True, type="string"), List[str]) -assert_type(IniFile().get("some_key", locale=False, list=True, type="string"), List[str]) -assert_type(IniFile().get("some_key", locale=True, list=True, type="string"), List[str]) -assert_type(IniFile().get("some_key", strict=False, list=True, type="string"), List[str]) -assert_type(IniFile().get("some_key", strict=True, list=True, type="string"), List[str]) -assert_type(IniFile().get("some_key", group="group", locale=True, strict=True, list=True, type="string"), List[str]) +assert_type(IniFile().get("some_key", list=True, type="string"), list[str]) +assert_type(IniFile().get("some_key", group=None, list=True, type="string"), list[str]) +assert_type(IniFile().get("some_key", group="group", list=True, type="string"), list[str]) +assert_type(IniFile().get("some_key", locale=False, list=True, type="string"), list[str]) +assert_type(IniFile().get("some_key", locale=True, list=True, type="string"), list[str]) +assert_type(IniFile().get("some_key", strict=False, list=True, type="string"), list[str]) +assert_type(IniFile().get("some_key", strict=True, list=True, type="string"), list[str]) +assert_type(IniFile().get("some_key", group="group", locale=True, strict=True, list=True, type="string"), list[str]) # Get bool assert_type(IniFile().get("some_key", "group", True, "boolean"), bool) @@ -112,19 +111,19 @@ assert_type(IniFile().get("some_key", type="boolean", strict=True, list=False), bool) assert_type(IniFile().get("some_key", type="boolean", group="group", locale=True, strict=True, list=False), bool) -# Get List[bool] -assert_type(IniFile().get("some_key", "group", True, "boolean", True), List[bool]) -assert_type(IniFile().get("some_key", "group", True, "boolean", True, False), List[bool]) -assert_type(IniFile().get("some_key", "group", True, "boolean", True, True), List[bool]) +# Get list[bool] +assert_type(IniFile().get("some_key", "group", True, "boolean", True), list[bool]) +assert_type(IniFile().get("some_key", "group", True, "boolean", True, False), list[bool]) +assert_type(IniFile().get("some_key", "group", True, "boolean", True, True), list[bool]) # Keyword parameters -assert_type(IniFile().get("some_key", type="boolean", list=True), List[bool]) -assert_type(IniFile().get("some_key", type="boolean", list=True, group=None), List[bool]) -assert_type(IniFile().get("some_key", type="boolean", list=True, group="group"), List[bool]) -assert_type(IniFile().get("some_key", type="boolean", list=True, locale=False), List[bool]) -assert_type(IniFile().get("some_key", type="boolean", list=True, locale=True), List[bool]) -assert_type(IniFile().get("some_key", type="boolean", list=True, strict=False), List[bool]) -assert_type(IniFile().get("some_key", type="boolean", list=True, strict=True), List[bool]) -assert_type(IniFile().get("some_key", type="boolean", list=True, group="group", locale=True, strict=True), List[bool]) +assert_type(IniFile().get("some_key", type="boolean", list=True), list[bool]) +assert_type(IniFile().get("some_key", type="boolean", list=True, group=None), list[bool]) +assert_type(IniFile().get("some_key", type="boolean", list=True, group="group"), list[bool]) +assert_type(IniFile().get("some_key", type="boolean", list=True, locale=False), list[bool]) +assert_type(IniFile().get("some_key", type="boolean", list=True, locale=True), list[bool]) +assert_type(IniFile().get("some_key", type="boolean", list=True, strict=False), list[bool]) +assert_type(IniFile().get("some_key", type="boolean", list=True, strict=True), list[bool]) +assert_type(IniFile().get("some_key", type="boolean", list=True, group="group", locale=True, strict=True), list[bool]) # Get int assert_type(IniFile().get("some_key", "group", True, "integer"), int) @@ -150,19 +149,19 @@ assert_type(IniFile().get("some_key", type="integer", strict=True, list=False), int) assert_type(IniFile().get("some_key", type="integer", group="group", locale=True, strict=True, list=False), int) -# Get List[int] -assert_type(IniFile().get("some_key", "group", True, "integer", True), List[int]) -assert_type(IniFile().get("some_key", "group", True, "integer", True, False), List[int]) -assert_type(IniFile().get("some_key", "group", True, "integer", True, True), List[int]) +# Get list[int] +assert_type(IniFile().get("some_key", "group", True, "integer", True), list[int]) +assert_type(IniFile().get("some_key", "group", True, "integer", True, False), list[int]) +assert_type(IniFile().get("some_key", "group", True, "integer", True, True), list[int]) # Keyword parameters -assert_type(IniFile().get("some_key", type="integer", list=True), List[int]) -assert_type(IniFile().get("some_key", type="integer", list=True, group=None), List[int]) -assert_type(IniFile().get("some_key", type="integer", list=True, group="group"), List[int]) -assert_type(IniFile().get("some_key", type="integer", list=True, locale=False), List[int]) -assert_type(IniFile().get("some_key", type="integer", list=True, locale=True), List[int]) -assert_type(IniFile().get("some_key", type="integer", list=True, strict=False), List[int]) -assert_type(IniFile().get("some_key", type="integer", list=True, strict=True), List[int]) -assert_type(IniFile().get("some_key", type="integer", list=True, group="group", locale=True, strict=True), List[int]) +assert_type(IniFile().get("some_key", type="integer", list=True), list[int]) +assert_type(IniFile().get("some_key", type="integer", list=True, group=None), list[int]) +assert_type(IniFile().get("some_key", type="integer", list=True, group="group"), list[int]) +assert_type(IniFile().get("some_key", type="integer", list=True, locale=False), list[int]) +assert_type(IniFile().get("some_key", type="integer", list=True, locale=True), list[int]) +assert_type(IniFile().get("some_key", type="integer", list=True, strict=False), list[int]) +assert_type(IniFile().get("some_key", type="integer", list=True, strict=True), list[int]) +assert_type(IniFile().get("some_key", type="integer", list=True, group="group", locale=True, strict=True), list[int]) # Get float assert_type(IniFile().get("some_key", "group", True, "numeric"), float) @@ -188,19 +187,19 @@ assert_type(IniFile().get("some_key", type="numeric", strict=True, list=False), float) assert_type(IniFile().get("some_key", type="numeric", group="group", locale=True, strict=True, list=False), float) -# Get List[float] -assert_type(IniFile().get("some_key", "group", True, "numeric", True), List[float]) -assert_type(IniFile().get("some_key", "group", True, "numeric", True, False), List[float]) -assert_type(IniFile().get("some_key", "group", True, "numeric", True, True), List[float]) +# Get list[float] +assert_type(IniFile().get("some_key", "group", True, "numeric", True), list[float]) +assert_type(IniFile().get("some_key", "group", True, "numeric", True, False), list[float]) +assert_type(IniFile().get("some_key", "group", True, "numeric", True, True), list[float]) # Keyword parameters -assert_type(IniFile().get("some_key", type="numeric", list=True), List[float]) -assert_type(IniFile().get("some_key", type="numeric", list=True, group=None), List[float]) -assert_type(IniFile().get("some_key", type="numeric", list=True, group="group"), List[float]) -assert_type(IniFile().get("some_key", type="numeric", list=True, locale=False), List[float]) -assert_type(IniFile().get("some_key", type="numeric", list=True, locale=True), List[float]) -assert_type(IniFile().get("some_key", type="numeric", list=True, strict=False), List[float]) -assert_type(IniFile().get("some_key", type="numeric", list=True, strict=True), List[float]) -assert_type(IniFile().get("some_key", type="numeric", list=True, group="group", locale=True, strict=True), List[float]) +assert_type(IniFile().get("some_key", type="numeric", list=True), list[float]) +assert_type(IniFile().get("some_key", type="numeric", list=True, group=None), list[float]) +assert_type(IniFile().get("some_key", type="numeric", list=True, group="group"), list[float]) +assert_type(IniFile().get("some_key", type="numeric", list=True, locale=False), list[float]) +assert_type(IniFile().get("some_key", type="numeric", list=True, locale=True), list[float]) +assert_type(IniFile().get("some_key", type="numeric", list=True, strict=False), list[float]) +assert_type(IniFile().get("some_key", type="numeric", list=True, strict=True), list[float]) +assert_type(IniFile().get("some_key", type="numeric", list=True, group="group", locale=True, strict=True), list[float]) # Get regex assert_type(IniFile().get("some_key", "group", True, "regex"), re.Pattern[str]) @@ -226,54 +225,54 @@ assert_type(IniFile().get("some_key", type="regex", strict=True, list=False), re.Pattern[str]) assert_type(IniFile().get("some_key", type="regex", group="group", locale=True, strict=True, list=False), re.Pattern[str]) -# Get List[regex] -assert_type(IniFile().get("some_key", "group", True, "regex", True), List[re.Pattern[str]]) -assert_type(IniFile().get("some_key", "group", True, "regex", True, False), List[re.Pattern[str]]) -assert_type(IniFile().get("some_key", "group", True, "regex", True, True), List[re.Pattern[str]]) +# Get list[regex] +assert_type(IniFile().get("some_key", "group", True, "regex", True), list[re.Pattern[str]]) +assert_type(IniFile().get("some_key", "group", True, "regex", True, False), list[re.Pattern[str]]) +assert_type(IniFile().get("some_key", "group", True, "regex", True, True), list[re.Pattern[str]]) # Keyword parameters -assert_type(IniFile().get("some_key", type="regex", list=True), List[re.Pattern[str]]) -assert_type(IniFile().get("some_key", type="regex", list=True, group=None), List[re.Pattern[str]]) -assert_type(IniFile().get("some_key", type="regex", list=True, group="group"), List[re.Pattern[str]]) -assert_type(IniFile().get("some_key", type="regex", list=True, locale=False), List[re.Pattern[str]]) -assert_type(IniFile().get("some_key", type="regex", list=True, locale=True), List[re.Pattern[str]]) -assert_type(IniFile().get("some_key", type="regex", list=True, strict=False), List[re.Pattern[str]]) -assert_type(IniFile().get("some_key", type="regex", list=True, strict=True), List[re.Pattern[str]]) -assert_type(IniFile().get("some_key", type="regex", list=True, group="group", locale=True, strict=True), List[re.Pattern[str]]) +assert_type(IniFile().get("some_key", type="regex", list=True), list[re.Pattern[str]]) +assert_type(IniFile().get("some_key", type="regex", list=True, group=None), list[re.Pattern[str]]) +assert_type(IniFile().get("some_key", type="regex", list=True, group="group"), list[re.Pattern[str]]) +assert_type(IniFile().get("some_key", type="regex", list=True, locale=False), list[re.Pattern[str]]) +assert_type(IniFile().get("some_key", type="regex", list=True, locale=True), list[re.Pattern[str]]) +assert_type(IniFile().get("some_key", type="regex", list=True, strict=False), list[re.Pattern[str]]) +assert_type(IniFile().get("some_key", type="regex", list=True, strict=True), list[re.Pattern[str]]) +assert_type(IniFile().get("some_key", type="regex", list=True, group="group", locale=True, strict=True), list[re.Pattern[str]]) # Get point -assert_type(IniFile().get("some_key", "group", True, "point"), Tuple[int, int]) -assert_type(IniFile().get("some_key", "group", True, "point", False), Tuple[int, int]) -assert_type(IniFile().get("some_key", "group", True, "point", False, False), Tuple[int, int]) -assert_type(IniFile().get("some_key", "group", True, "point", False, True), Tuple[int, int]) +assert_type(IniFile().get("some_key", "group", True, "point"), tuple[int, int]) +assert_type(IniFile().get("some_key", "group", True, "point", False), tuple[int, int]) +assert_type(IniFile().get("some_key", "group", True, "point", False, False), tuple[int, int]) +assert_type(IniFile().get("some_key", "group", True, "point", False, True), tuple[int, int]) # Keyword parameters -assert_type(IniFile().get("some_key", type="point"), Tuple[int, int]) -assert_type(IniFile().get("some_key", type="point", group=None), Tuple[int, int]) -assert_type(IniFile().get("some_key", type="point", group="group"), Tuple[int, int]) -assert_type(IniFile().get("some_key", type="point", locale=False), Tuple[int, int]) -assert_type(IniFile().get("some_key", type="point", locale=True), Tuple[int, int]) -assert_type(IniFile().get("some_key", type="point", strict=False), Tuple[int, int]) -assert_type(IniFile().get("some_key", type="point", strict=True), Tuple[int, int]) -assert_type(IniFile().get("some_key", type="point", group="group", locale=True, strict=True), Tuple[int, int]) +assert_type(IniFile().get("some_key", type="point"), tuple[int, int]) +assert_type(IniFile().get("some_key", type="point", group=None), tuple[int, int]) +assert_type(IniFile().get("some_key", type="point", group="group"), tuple[int, int]) +assert_type(IniFile().get("some_key", type="point", locale=False), tuple[int, int]) +assert_type(IniFile().get("some_key", type="point", locale=True), tuple[int, int]) +assert_type(IniFile().get("some_key", type="point", strict=False), tuple[int, int]) +assert_type(IniFile().get("some_key", type="point", strict=True), tuple[int, int]) +assert_type(IniFile().get("some_key", type="point", group="group", locale=True, strict=True), tuple[int, int]) # Explicitly set list. -assert_type(IniFile().get("some_key", type="point", list=False), Tuple[int, int]) -assert_type(IniFile().get("some_key", type="point", group=None, list=False), Tuple[int, int]) -assert_type(IniFile().get("some_key", type="point", group="group", list=False), Tuple[int, int]) -assert_type(IniFile().get("some_key", type="point", locale=False, list=False), Tuple[int, int]) -assert_type(IniFile().get("some_key", type="point", locale=True, list=False), Tuple[int, int]) -assert_type(IniFile().get("some_key", type="point", strict=False, list=False), Tuple[int, int]) -assert_type(IniFile().get("some_key", type="point", strict=True, list=False), Tuple[int, int]) -assert_type(IniFile().get("some_key", type="point", group="group", locale=True, strict=True, list=False), Tuple[int, int]) +assert_type(IniFile().get("some_key", type="point", list=False), tuple[int, int]) +assert_type(IniFile().get("some_key", type="point", group=None, list=False), tuple[int, int]) +assert_type(IniFile().get("some_key", type="point", group="group", list=False), tuple[int, int]) +assert_type(IniFile().get("some_key", type="point", locale=False, list=False), tuple[int, int]) +assert_type(IniFile().get("some_key", type="point", locale=True, list=False), tuple[int, int]) +assert_type(IniFile().get("some_key", type="point", strict=False, list=False), tuple[int, int]) +assert_type(IniFile().get("some_key", type="point", strict=True, list=False), tuple[int, int]) +assert_type(IniFile().get("some_key", type="point", group="group", locale=True, strict=True, list=False), tuple[int, int]) -# Get List[point] -assert_type(IniFile().get("some_key", "group", True, "point", True), List[Tuple[int, int]]) -assert_type(IniFile().get("some_key", "group", True, "point", True, False), List[Tuple[int, int]]) -assert_type(IniFile().get("some_key", "group", True, "point", True, True), List[Tuple[int, int]]) +# Get list[point] +assert_type(IniFile().get("some_key", "group", True, "point", True), list[tuple[int, int]]) +assert_type(IniFile().get("some_key", "group", True, "point", True, False), list[tuple[int, int]]) +assert_type(IniFile().get("some_key", "group", True, "point", True, True), list[tuple[int, int]]) # Keyword parameters -assert_type(IniFile().get("some_key", type="point", list=True), List[Tuple[int, int]]) -assert_type(IniFile().get("some_key", type="point", list=True, group=None), List[Tuple[int, int]]) -assert_type(IniFile().get("some_key", type="point", list=True, group="group"), List[Tuple[int, int]]) -assert_type(IniFile().get("some_key", type="point", list=True, locale=False), List[Tuple[int, int]]) -assert_type(IniFile().get("some_key", type="point", list=True, locale=True), List[Tuple[int, int]]) -assert_type(IniFile().get("some_key", type="point", list=True, strict=False), List[Tuple[int, int]]) -assert_type(IniFile().get("some_key", type="point", list=True, strict=True), List[Tuple[int, int]]) -assert_type(IniFile().get("some_key", type="point", list=True, group="group", locale=True, strict=True), List[Tuple[int, int]]) +assert_type(IniFile().get("some_key", type="point", list=True), list[tuple[int, int]]) +assert_type(IniFile().get("some_key", type="point", list=True, group=None), list[tuple[int, int]]) +assert_type(IniFile().get("some_key", type="point", list=True, group="group"), list[tuple[int, int]]) +assert_type(IniFile().get("some_key", type="point", list=True, locale=False), list[tuple[int, int]]) +assert_type(IniFile().get("some_key", type="point", list=True, locale=True), list[tuple[int, int]]) +assert_type(IniFile().get("some_key", type="point", list=True, strict=False), list[tuple[int, int]]) +assert_type(IniFile().get("some_key", type="point", list=True, strict=True), list[tuple[int, int]]) +assert_type(IniFile().get("some_key", type="point", list=True, group="group", locale=True, strict=True), list[tuple[int, int]]) diff --git a/stubs/regex/@tests/test_cases/check_finditer.py b/stubs/regex/@tests/test_cases/check_finditer.py index 0b572973ceaf..1b2576736d75 100644 --- a/stubs/regex/@tests/test_cases/check_finditer.py +++ b/stubs/regex/@tests/test_cases/check_finditer.py @@ -1,11 +1,10 @@ from __future__ import annotations -from typing import List from typing_extensions import assert_type import regex # Regression tests for #9263 -assert_type(list(regex.finditer(r"foo", "foo")), List[regex.Match[str]]) +assert_type(list(regex.finditer(r"foo", "foo")), list[regex.Match[str]]) pat = regex.compile(rb"foo") -assert_type(list(pat.finditer(b"foo")), List[regex.Match[bytes]]) +assert_type(list(pat.finditer(b"foo")), list[regex.Match[bytes]])