Skip to content

Commit 7e16c80

Browse files
srittauAlexWaygoodpre-commit-ci[bot]
authored
Remove some pytype workarounds from stdlib (#14470)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 1a256d8 commit 7e16c80

File tree

8 files changed

+10
-40
lines changed

8 files changed

+10
-40
lines changed

stdlib/@tests/stubtest_allowlists/common.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,6 @@ typing(_extensions)?\.Generic
470470
typing(_extensions)?\.TypedDict
471471
typing_extensions\.ParamSpec.*
472472
typing_extensions\.TypeVar.*
473-
typing_extensions\._SpecialForm.*
474473

475474
# Special primitives
476475
typing(_extensions)?\.AbstractSet
@@ -499,7 +498,6 @@ typing(_extensions)?\.Reversible
499498
typing(_extensions)?\.Sequence
500499
typing(_extensions)?\.Sized
501500
typing(_extensions)?\.ValuesView
502-
typing_extensions\.Final
503501
typing_extensions\.LiteralString
504502

505503
# Typing-related weirdness

stdlib/asyncio/base_futures.pyi

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1+
from _asyncio import Future
12
from collections.abc import Callable, Sequence
23
from contextvars import Context
34
from typing import Any, Final
5+
from typing_extensions import TypeIs
46

57
from . import futures
68

79
__all__ = ()
810

9-
# asyncio defines 'isfuture()' in base_futures.py and re-imports it in futures.py
10-
# but it leads to circular import error in pytype tool.
11-
# That's why the import order is reversed.
12-
from .futures import isfuture as isfuture
13-
1411
_PENDING: Final = "PENDING" # undocumented
1512
_CANCELLED: Final = "CANCELLED" # undocumented
1613
_FINISHED: Final = "FINISHED" # undocumented
1714

15+
def isfuture(obj: object) -> TypeIs[Future[Any]]: ...
1816
def _format_callbacks(cb: Sequence[tuple[Callable[[futures.Future[Any]], None], Context]]) -> str: ... # undocumented
1917
def _future_repr_info(future: futures.Future[Any]) -> list[str]: ... # undocumented

stdlib/asyncio/futures.pyi

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import sys
22
from _asyncio import Future as Future
33
from concurrent.futures._base import Future as _ConcurrentFuture
4-
from typing import Any, TypeVar
5-
from typing_extensions import TypeIs
4+
from typing import TypeVar
65

6+
from .base_futures import isfuture as isfuture
77
from .events import AbstractEventLoop
88

99
# Keep asyncio.__all__ updated with any changes to __all__ here
@@ -16,8 +16,4 @@ else:
1616

1717
_T = TypeVar("_T")
1818

19-
# asyncio defines 'isfuture()' in base_futures.py and re-imports it in futures.py
20-
# but it leads to circular import error in pytype tool.
21-
# That's why the import order is reversed.
22-
def isfuture(obj: object) -> TypeIs[Future[Any]]: ...
2319
def wrap_future(future: _ConcurrentFuture[_T] | Future[_T], *, loop: AbstractEventLoop | None = None) -> Future[_T]: ...

stdlib/builtins.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1526,7 +1526,6 @@ def iter(object: Callable[[], _T | None], sentinel: None, /) -> Iterator[_T]: ..
15261526
@overload
15271527
def iter(object: Callable[[], _T], sentinel: object, /) -> Iterator[_T]: ...
15281528

1529-
# Keep this alias in sync with unittest.case._ClassInfo
15301529
if sys.version_info >= (3, 10):
15311530
_ClassInfo: TypeAlias = type | types.UnionType | tuple[_ClassInfo, ...]
15321531
else:

stdlib/optparse.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ __all__ = [
2424
"BadOptionError",
2525
"check_choice",
2626
]
27-
# pytype is not happy with `NO_DEFAULT: Final = ("NO", "DEFAULT")`
28-
NO_DEFAULT: Final[tuple[Literal["NO"], Literal["DEFAULT"]]]
27+
NO_DEFAULT: Final = ("NO", "DEFAULT")
2928
SUPPRESS_HELP: Final = "SUPPRESSHELP"
3029
SUPPRESS_USAGE: Final = "SUPPRESSUSAGE"
3130

stdlib/re.pyi

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,7 @@ if sys.version_info < (3, 13):
239239
T: Final = RegexFlag.T
240240
TEMPLATE: Final = RegexFlag.TEMPLATE
241241
if sys.version_info >= (3, 11):
242-
# pytype chokes on `NOFLAG: Final = RegexFlag.NOFLAG` with `LiteralValueError`
243-
# mypy chokes on `NOFLAG: Final[Literal[RegexFlag.NOFLAG]]` with `Literal[...] is invalid`
244-
NOFLAG = RegexFlag.NOFLAG
242+
NOFLAG: Final = RegexFlag.NOFLAG
245243
_FlagsType: TypeAlias = int | RegexFlag
246244

247245
# Type-wise the compile() overloads are unnecessary, they could also be modeled using

stdlib/typing_extensions.pyi

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ from typing import ( # noqa: Y022,Y037,Y038,Y039,UP035
5959
TypeVar as _TypeVar,
6060
Union as Union,
6161
_Alias,
62+
_SpecialForm,
6263
cast as cast,
6364
no_type_check as no_type_check,
6465
no_type_check_decorator as no_type_check_decorator,
@@ -204,15 +205,6 @@ _TC = _TypeVar("_TC", bound=type[object])
204205
_T_co = _TypeVar("_T_co", covariant=True) # Any type covariant containers.
205206
_T_contra = _TypeVar("_T_contra", contravariant=True)
206207

207-
class _Final: ... # This should be imported from typing but that breaks pytype
208-
209-
# unfortunately we have to duplicate this class definition from typing.pyi or we break pytype
210-
class _SpecialForm(_Final):
211-
def __getitem__(self, parameters: Any) -> object: ...
212-
if sys.version_info >= (3, 10):
213-
def __or__(self, other: Any) -> _SpecialForm: ...
214-
def __ror__(self, other: Any) -> _SpecialForm: ...
215-
216208
# Do not import (and re-export) Protocol or runtime_checkable from
217209
# typing module because type checkers need to be able to distinguish
218210
# typing.Protocol and typing_extensions.Protocol so they can properly

stdlib/unittest/case.pyi

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@ import logging
22
import sys
33
import unittest.result
44
from _typeshed import SupportsDunderGE, SupportsDunderGT, SupportsDunderLE, SupportsDunderLT, SupportsRSub, SupportsSub
5+
from builtins import _ClassInfo
56
from collections.abc import Callable, Container, Iterable, Mapping, Sequence, Set as AbstractSet
67
from contextlib import AbstractContextManager
78
from re import Pattern
89
from types import GenericAlias, TracebackType
910
from typing import Any, AnyStr, Final, Generic, NoReturn, Protocol, SupportsAbs, SupportsRound, TypeVar, overload
10-
from typing_extensions import Never, ParamSpec, Self, TypeAlias
11+
from typing_extensions import Never, ParamSpec, Self
1112
from unittest._log import _AssertLogsContext, _LoggingWatcher
1213
from warnings import WarningMessage
1314

14-
if sys.version_info >= (3, 10):
15-
from types import UnionType
16-
1715
_T = TypeVar("_T")
1816
_S = TypeVar("_S", bound=SupportsSub[Any, Any])
1917
_E = TypeVar("_E", bound=BaseException)
@@ -60,14 +58,6 @@ class SkipTest(Exception):
6058

6159
class _SupportsAbsAndDunderGE(SupportsDunderGE[Any], SupportsAbs[Any], Protocol): ...
6260

63-
# Keep this alias in sync with builtins._ClassInfo
64-
# We can't import it from builtins or pytype crashes,
65-
# due to the fact that pytype uses a custom builtins stub rather than typeshed's builtins stub
66-
if sys.version_info >= (3, 10):
67-
_ClassInfo: TypeAlias = type | UnionType | tuple[_ClassInfo, ...]
68-
else:
69-
_ClassInfo: TypeAlias = type | tuple[_ClassInfo, ...]
70-
7161
class TestCase:
7262
failureException: type[BaseException]
7363
longMessage: bool

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy