From 7ce4607dee8a90474261f96f90b03452bd3d835f Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Sun, 17 Apr 2022 01:23:35 +0100 Subject: [PATCH] Upgrade flake8-pyi to 22.4.0, enable Y026 in `.flake8` config (#7650) --- .flake8 | 7 +++---- requirements-tests.txt | 2 +- stdlib/builtins.pyi | 6 ++++-- stdlib/typing.pyi | 6 ++++-- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.flake8 b/.flake8 index 3b8915458..ee79a2a35 100644 --- a/.flake8 +++ b/.flake8 @@ -18,7 +18,6 @@ # F405 defined from star imports # Rules that we'd like to enable in the future: -# Y026 Use typing_extensions.TypeAlias for type aliases (blocked by #4913) # Y027 Disallow importing typing.ContextManager, typing.OrderedDict & # typing_extensions.OrderedDict (cannot be globally enabled while typeshed # still contains stubs supporting Python 2). @@ -32,12 +31,12 @@ [flake8] per-file-ignores = *.py: E203, E501 - *.pyi: E301, E302, E305, E501, E701, E741, F401, F403, F405, F822, Y026, Y037 + *.pyi: E301, E302, E305, E501, E701, E741, F401, F403, F405, F822, Y037 # Since typing.pyi defines "overload" this is not recognized by flake8 as typing.overload. # Unfortunately, flake8 does not allow to "noqa" just a specific error inside the file itself. # https://github.com/PyCQA/flake8/issues/1079 # F811 redefinition of unused '...' - stubs/*.pyi: E301, E302, E305, E501, E701, E741, F401, F403, F405, F822, Y026, Y027, Y037 - stdlib/typing.pyi: E301, E302, E305, E501, E701, E741, F401, F403, F405, F811, F822, Y026, Y034, Y037 + stubs/*.pyi: E301, E302, E305, E501, E701, E741, F401, F403, F405, F822, Y027, Y037 + stdlib/typing.pyi: E301, E302, E305, E501, E701, E741, F401, F403, F405, F811, F822, Y034, Y037 exclude = .venv*,.git,*_pb2.pyi,stdlib/@python2/* diff --git a/requirements-tests.txt b/requirements-tests.txt index cb362d946..af702774c 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -4,7 +4,7 @@ pytype==2022.03.29; platform_system != "Windows" and python_version < "3.10" black==22.3.0 flake8==4.0.1 flake8-bugbear==21.11.29 -flake8-pyi==22.3.0 +flake8-pyi==22.4.0 # must match .pre-commit-config.yaml isort==5.10.1 tomli==1.2.2 diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index cda4cd1f6..5db5de3db 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -1289,7 +1289,7 @@ def next(__i: SupportsNext[_T]) -> _T: ... def next(__i: SupportsNext[_T], __default: _VT) -> _T | _VT: ... def oct(__number: int | SupportsIndex) -> str: ... -_OpenFile = StrOrBytesPath | int +_OpenFile = StrOrBytesPath | int # noqa: Y026 # TODO: Use TypeAlias once mypy bugs are fixed _Opener: TypeAlias = Callable[[str, int], int] # Text mode: always returns a TextIOWrapper @@ -1408,7 +1408,9 @@ class _SupportsPow3NoneOnly(Protocol[_E, _T_co]): class _SupportsPow3(Protocol[_E, _M, _T_co]): def __pow__(self, __other: _E, __modulo: _M) -> _T_co: ... -_SupportsSomeKindOfPow = _SupportsPow2[Any, Any] | _SupportsPow3NoneOnly[Any, Any] | _SupportsPow3[Any, Any, Any] +_SupportsSomeKindOfPow = ( # noqa: Y026 # TODO: Use TypeAlias once mypy bugs are fixed + _SupportsPow2[Any, Any] | _SupportsPow3NoneOnly[Any, Any] | _SupportsPow3[Any, Any, Any] +) if sys.version_info >= (3, 8): @overload diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index 994360586..28b588d79 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -1146,7 +1146,7 @@ class Pattern(Generic[AnyStr]): # Functions if sys.version_info >= (3, 7): - _get_type_hints_obj_allowed_types = ( + _get_type_hints_obj_allowed_types = ( # noqa: Y026 # TODO: Use TypeAlias once mypy bugs are fixed object | Callable[..., Any] | FunctionType @@ -1158,7 +1158,9 @@ if sys.version_info >= (3, 7): | MethodDescriptorType ) else: - _get_type_hints_obj_allowed_types = object | Callable[..., Any] | FunctionType | BuiltinFunctionType | MethodType | ModuleType + _get_type_hints_obj_allowed_types = ( # noqa: Y026 # TODO: Use TypeAlias once mypy bugs are fixed + object | Callable[..., Any] | FunctionType | BuiltinFunctionType | MethodType | ModuleType + ) if sys.version_info >= (3, 9): def get_type_hints(