Skip to content

Commit 0ef9c3f

Browse files
authored
Enable flake8-pyi's Y037 (#9686)
1 parent c4c4bee commit 0ef9c3f

File tree

38 files changed

+119
-201
lines changed

38 files changed

+119
-201
lines changed

.flake8

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,15 @@
1818
# F403 import *' used; unable to detect undefined names
1919
# F405 defined from star imports
2020

21-
# Rules that we'd like to enable in the future:
22-
# Y037 Use PEP 604 syntax instead of `typing.Union` and `typing.Optional`.
23-
# Currently can't be enabled due to a few lingering bugs in mypy regarding
24-
# PEP 604 type aliases (see #4819).
25-
2621
[flake8]
2722
per-file-ignores =
2823
*.py: E203, E301, E302, E305, E501
29-
*.pyi: B, E301, E302, E305, E501, E701, E741, F401, F403, F405, F822, Y037
24+
*.pyi: B, E301, E302, E305, E501, E701, E741, F401, F403, F405, F822
3025
# Since typing.pyi defines "overload" this is not recognized by flake8 as typing.overload.
3126
# Unfortunately, flake8 does not allow to "noqa" just a specific error inside the file itself.
3227
# https://github.com/PyCQA/flake8/issues/1079
3328
# F811 redefinition of unused '...'
34-
stdlib/typing.pyi: B, E301, E302, E305, E501, E701, E741, F401, F403, F405, F811, F822, Y037
29+
stdlib/typing.pyi: B, E301, E302, E305, E501, E701, E741, F401, F403, F405, F811, F822
3530
# Generated protobuf files include docstrings
3631
*_pb2.pyi: B, E301, E302, E305, E501, E701, Y021, Y026
3732

stdlib/_csv.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from _typeshed import SupportsWrite
22
from collections.abc import Iterable, Iterator
3-
from typing import Any, Union
3+
from typing import Any
44
from typing_extensions import Literal, TypeAlias
55

66
__version__: str
@@ -27,7 +27,7 @@ class Dialect:
2727
strict: bool
2828
def __init__(self) -> None: ...
2929

30-
_DialectLike: TypeAlias = Union[str, Dialect, type[Dialect]]
30+
_DialectLike: TypeAlias = str | Dialect | type[Dialect]
3131

3232
class _reader(Iterator[list[str]]):
3333
@property

stdlib/_decimal.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import sys
33
from _typeshed import Self
44
from collections.abc import Container, Sequence
55
from types import TracebackType
6-
from typing import Any, ClassVar, NamedTuple, Union, overload
6+
from typing import Any, ClassVar, NamedTuple, overload
77
from typing_extensions import Literal, TypeAlias
88

99
_Decimal: TypeAlias = Decimal | int
10-
_DecimalNew: TypeAlias = Union[Decimal, float, str, tuple[int, Sequence[int], int]]
10+
_DecimalNew: TypeAlias = Decimal | float | str | tuple[int, Sequence[int], int]
1111
_ComparableNum: TypeAlias = Decimal | float | numbers.Rational
1212

1313
__version__: str

stdlib/_typeshed/__init__.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ from collections.abc import Awaitable, Callable, Iterable, Set as AbstractSet
1111
from dataclasses import Field
1212
from os import PathLike
1313
from types import FrameType, TracebackType
14-
from typing import Any, AnyStr, ClassVar, Generic, Protocol, TypeVar, Union
14+
from typing import Any, AnyStr, ClassVar, Generic, Protocol, TypeVar
1515
from typing_extensions import Final, Literal, LiteralString, TypeAlias, final
1616

1717
_KT = TypeVar("_KT")
@@ -265,7 +265,7 @@ IndexableBuffer: TypeAlias = bytes | bytearray | memoryview | array.array[Any] |
265265
# def __buffer__(self, __flags: int) -> memoryview: ...
266266

267267
ExcInfo: TypeAlias = tuple[type[BaseException], BaseException, TracebackType]
268-
OptExcInfo: TypeAlias = Union[ExcInfo, tuple[None, None, None]]
268+
OptExcInfo: TypeAlias = ExcInfo | tuple[None, None, None]
269269

270270
# stable
271271
if sys.version_info >= (3, 10):

stdlib/copyreg.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from collections.abc import Callable, Hashable
2-
from typing import Any, SupportsInt, TypeVar, Union
2+
from typing import Any, SupportsInt, TypeVar
33
from typing_extensions import TypeAlias
44

55
_T = TypeVar("_T")
6-
_Reduce: TypeAlias = Union[tuple[Callable[..., _T], tuple[Any, ...]], tuple[Callable[..., _T], tuple[Any, ...], Any | None]]
6+
_Reduce: TypeAlias = tuple[Callable[..., _T], tuple[Any, ...]] | tuple[Callable[..., _T], tuple[Any, ...], Any | None]
77

88
__all__ = ["pickle", "constructor", "add_extension", "remove_extension", "clear_extension_cache"]
99

stdlib/ctypes/__init__.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ from _ctypes import RTLD_GLOBAL as RTLD_GLOBAL, RTLD_LOCAL as RTLD_LOCAL
33
from _typeshed import ReadableBuffer, Self, WriteableBuffer
44
from abc import abstractmethod
55
from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence
6-
from typing import Any, ClassVar, Generic, TypeVar, Union as _UnionT, overload
6+
from typing import Any, ClassVar, Generic, TypeVar, overload
77
from typing_extensions import TypeAlias
88

99
if sys.version_info >= (3, 9):
@@ -91,7 +91,7 @@ class _CanCastTo(_CData): ...
9191
class _PointerLike(_CanCastTo): ...
9292

9393
_ECT: TypeAlias = Callable[[type[_CData] | None, _FuncPointer, tuple[_CData, ...]], _CData]
94-
_PF: TypeAlias = _UnionT[tuple[int], tuple[int, str], tuple[int, str, Any]]
94+
_PF: TypeAlias = tuple[int] | tuple[int, str] | tuple[int, str, Any]
9595

9696
class _FuncPointer(_PointerLike, _CData):
9797
restype: type[_CData] | Callable[[int], Any] | None

stdlib/distutils/ccompiler.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from collections.abc import Callable
2-
from typing import Any, Union
2+
from typing import Any
33
from typing_extensions import TypeAlias
44

5-
_Macro: TypeAlias = Union[tuple[str], tuple[str, str | None]]
5+
_Macro: TypeAlias = tuple[str] | tuple[str, str | None]
66

77
def gen_lib_options(
88
compiler: CCompiler, library_dirs: list[str], runtime_library_dirs: list[str], libraries: list[str]

stdlib/email/__init__.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from collections.abc import Callable
22
from email.message import Message
33
from email.policy import Policy
4-
from typing import IO, Union
4+
from typing import IO
55
from typing_extensions import TypeAlias
66

77
# Definitions imported by multiple submodules in typeshed
8-
_ParamType: TypeAlias = Union[str, tuple[str | None, str | None, str]] # noqa: Y047
9-
_ParamsType: TypeAlias = Union[str, None, tuple[str, str | None, str]] # noqa: Y047
8+
_ParamType: TypeAlias = str | tuple[str | None, str | None, str] # noqa: Y047
9+
_ParamsType: TypeAlias = str | None | tuple[str, str | None, str] # noqa: Y047
1010

1111
def message_from_string(s: str, _class: Callable[[], Message] = ..., *, policy: Policy = ...) -> Message: ...
1212
def message_from_bytes(s: bytes | bytearray, _class: Callable[[], Message] = ..., *, policy: Policy = ...) -> Message: ...

stdlib/inspect.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ from types import (
2525
TracebackType,
2626
WrapperDescriptorType,
2727
)
28-
from typing import Any, ClassVar, NamedTuple, Protocol, TypeVar, Union, overload
28+
from typing import Any, ClassVar, NamedTuple, Protocol, TypeVar, overload
2929
from typing_extensions import Literal, ParamSpec, TypeAlias, TypeGuard
3030

3131
if sys.version_info >= (3, 11):
@@ -264,9 +264,9 @@ def isdatadescriptor(object: object) -> TypeGuard[_SupportsSet[Any, Any] | _Supp
264264
#
265265
# Retrieving source code
266266
#
267-
_SourceObjectType: TypeAlias = Union[
268-
ModuleType, type[Any], MethodType, FunctionType, TracebackType, FrameType, CodeType, Callable[..., Any]
269-
]
267+
_SourceObjectType: TypeAlias = (
268+
ModuleType | type[Any] | MethodType | FunctionType | TracebackType | FrameType | CodeType | Callable[..., Any]
269+
)
270270

271271
def findsource(object: _SourceObjectType) -> tuple[list[str], int]: ...
272272
def getabsfile(object: _SourceObjectType, _filename: str | None = None) -> str: ...

stdlib/logging/__init__.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ from re import Pattern
77
from string import Template
88
from time import struct_time
99
from types import FrameType, TracebackType
10-
from typing import Any, ClassVar, Generic, TextIO, TypeVar, Union, overload
10+
from typing import Any, ClassVar, Generic, TextIO, TypeVar, overload
1111
from typing_extensions import Literal, TypeAlias
1212

1313
if sys.version_info >= (3, 11):
@@ -61,7 +61,7 @@ __all__ = [
6161
if sys.version_info >= (3, 11):
6262
__all__ += ["getLevelNamesMapping"]
6363

64-
_SysExcInfoType: TypeAlias = Union[tuple[type[BaseException], BaseException, TracebackType | None], tuple[None, None, None]]
64+
_SysExcInfoType: TypeAlias = tuple[type[BaseException], BaseException, TracebackType | None] | tuple[None, None, None]
6565
_ExcInfoType: TypeAlias = None | bool | _SysExcInfoType | BaseException
6666
_ArgsType: TypeAlias = tuple[object, ...] | Mapping[str, object]
6767
_FilterType: TypeAlias = Filter | Callable[[LogRecord], bool]

0 commit comments

Comments
 (0)