mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-05-06 21:43:59 +08:00
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>
This commit is contained in:
@@ -470,7 +470,6 @@ typing(_extensions)?\.Generic
|
||||
typing(_extensions)?\.TypedDict
|
||||
typing_extensions\.ParamSpec.*
|
||||
typing_extensions\.TypeVar.*
|
||||
typing_extensions\._SpecialForm.*
|
||||
|
||||
# Special primitives
|
||||
typing(_extensions)?\.AbstractSet
|
||||
@@ -499,7 +498,6 @@ typing(_extensions)?\.Reversible
|
||||
typing(_extensions)?\.Sequence
|
||||
typing(_extensions)?\.Sized
|
||||
typing(_extensions)?\.ValuesView
|
||||
typing_extensions\.Final
|
||||
typing_extensions\.LiteralString
|
||||
|
||||
# Typing-related weirdness
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
from _asyncio import Future
|
||||
from collections.abc import Callable, Sequence
|
||||
from contextvars import Context
|
||||
from typing import Any, Final
|
||||
from typing_extensions import TypeIs
|
||||
|
||||
from . import futures
|
||||
|
||||
__all__ = ()
|
||||
|
||||
# asyncio defines 'isfuture()' in base_futures.py and re-imports it in futures.py
|
||||
# but it leads to circular import error in pytype tool.
|
||||
# That's why the import order is reversed.
|
||||
from .futures import isfuture as isfuture
|
||||
|
||||
_PENDING: Final = "PENDING" # undocumented
|
||||
_CANCELLED: Final = "CANCELLED" # undocumented
|
||||
_FINISHED: Final = "FINISHED" # undocumented
|
||||
|
||||
def isfuture(obj: object) -> TypeIs[Future[Any]]: ...
|
||||
def _format_callbacks(cb: Sequence[tuple[Callable[[futures.Future[Any]], None], Context]]) -> str: ... # undocumented
|
||||
def _future_repr_info(future: futures.Future[Any]) -> list[str]: ... # undocumented
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import sys
|
||||
from _asyncio import Future as Future
|
||||
from concurrent.futures._base import Future as _ConcurrentFuture
|
||||
from typing import Any, TypeVar
|
||||
from typing_extensions import TypeIs
|
||||
from typing import TypeVar
|
||||
|
||||
from .base_futures import isfuture as isfuture
|
||||
from .events import AbstractEventLoop
|
||||
|
||||
# Keep asyncio.__all__ updated with any changes to __all__ here
|
||||
@@ -16,8 +16,4 @@ else:
|
||||
|
||||
_T = TypeVar("_T")
|
||||
|
||||
# asyncio defines 'isfuture()' in base_futures.py and re-imports it in futures.py
|
||||
# but it leads to circular import error in pytype tool.
|
||||
# That's why the import order is reversed.
|
||||
def isfuture(obj: object) -> TypeIs[Future[Any]]: ...
|
||||
def wrap_future(future: _ConcurrentFuture[_T] | Future[_T], *, loop: AbstractEventLoop | None = None) -> Future[_T]: ...
|
||||
|
||||
@@ -1526,7 +1526,6 @@ def iter(object: Callable[[], _T | None], sentinel: None, /) -> Iterator[_T]: ..
|
||||
@overload
|
||||
def iter(object: Callable[[], _T], sentinel: object, /) -> Iterator[_T]: ...
|
||||
|
||||
# Keep this alias in sync with unittest.case._ClassInfo
|
||||
if sys.version_info >= (3, 10):
|
||||
_ClassInfo: TypeAlias = type | types.UnionType | tuple[_ClassInfo, ...]
|
||||
else:
|
||||
|
||||
+1
-2
@@ -24,8 +24,7 @@ __all__ = [
|
||||
"BadOptionError",
|
||||
"check_choice",
|
||||
]
|
||||
# pytype is not happy with `NO_DEFAULT: Final = ("NO", "DEFAULT")`
|
||||
NO_DEFAULT: Final[tuple[Literal["NO"], Literal["DEFAULT"]]]
|
||||
NO_DEFAULT: Final = ("NO", "DEFAULT")
|
||||
SUPPRESS_HELP: Final = "SUPPRESSHELP"
|
||||
SUPPRESS_USAGE: Final = "SUPPRESSUSAGE"
|
||||
|
||||
|
||||
+1
-3
@@ -239,9 +239,7 @@ if sys.version_info < (3, 13):
|
||||
T: Final = RegexFlag.T
|
||||
TEMPLATE: Final = RegexFlag.TEMPLATE
|
||||
if sys.version_info >= (3, 11):
|
||||
# pytype chokes on `NOFLAG: Final = RegexFlag.NOFLAG` with `LiteralValueError`
|
||||
# mypy chokes on `NOFLAG: Final[Literal[RegexFlag.NOFLAG]]` with `Literal[...] is invalid`
|
||||
NOFLAG = RegexFlag.NOFLAG
|
||||
NOFLAG: Final = RegexFlag.NOFLAG
|
||||
_FlagsType: TypeAlias = int | RegexFlag
|
||||
|
||||
# Type-wise the compile() overloads are unnecessary, they could also be modeled using
|
||||
|
||||
@@ -59,6 +59,7 @@ from typing import ( # noqa: Y022,Y037,Y038,Y039,UP035
|
||||
TypeVar as _TypeVar,
|
||||
Union as Union,
|
||||
_Alias,
|
||||
_SpecialForm,
|
||||
cast as cast,
|
||||
no_type_check as no_type_check,
|
||||
no_type_check_decorator as no_type_check_decorator,
|
||||
@@ -204,15 +205,6 @@ _TC = _TypeVar("_TC", bound=type[object])
|
||||
_T_co = _TypeVar("_T_co", covariant=True) # Any type covariant containers.
|
||||
_T_contra = _TypeVar("_T_contra", contravariant=True)
|
||||
|
||||
class _Final: ... # This should be imported from typing but that breaks pytype
|
||||
|
||||
# unfortunately we have to duplicate this class definition from typing.pyi or we break pytype
|
||||
class _SpecialForm(_Final):
|
||||
def __getitem__(self, parameters: Any) -> object: ...
|
||||
if sys.version_info >= (3, 10):
|
||||
def __or__(self, other: Any) -> _SpecialForm: ...
|
||||
def __ror__(self, other: Any) -> _SpecialForm: ...
|
||||
|
||||
# Do not import (and re-export) Protocol or runtime_checkable from
|
||||
# typing module because type checkers need to be able to distinguish
|
||||
# typing.Protocol and typing_extensions.Protocol so they can properly
|
||||
|
||||
@@ -2,18 +2,16 @@ import logging
|
||||
import sys
|
||||
import unittest.result
|
||||
from _typeshed import SupportsDunderGE, SupportsDunderGT, SupportsDunderLE, SupportsDunderLT, SupportsRSub, SupportsSub
|
||||
from builtins import _ClassInfo
|
||||
from collections.abc import Callable, Container, Iterable, Mapping, Sequence, Set as AbstractSet
|
||||
from contextlib import AbstractContextManager
|
||||
from re import Pattern
|
||||
from types import GenericAlias, TracebackType
|
||||
from typing import Any, AnyStr, Final, Generic, NoReturn, Protocol, SupportsAbs, SupportsRound, TypeVar, overload
|
||||
from typing_extensions import Never, ParamSpec, Self, TypeAlias
|
||||
from typing_extensions import Never, ParamSpec, Self
|
||||
from unittest._log import _AssertLogsContext, _LoggingWatcher
|
||||
from warnings import WarningMessage
|
||||
|
||||
if sys.version_info >= (3, 10):
|
||||
from types import UnionType
|
||||
|
||||
_T = TypeVar("_T")
|
||||
_S = TypeVar("_S", bound=SupportsSub[Any, Any])
|
||||
_E = TypeVar("_E", bound=BaseException)
|
||||
@@ -60,14 +58,6 @@ class SkipTest(Exception):
|
||||
|
||||
class _SupportsAbsAndDunderGE(SupportsDunderGE[Any], SupportsAbs[Any], Protocol): ...
|
||||
|
||||
# Keep this alias in sync with builtins._ClassInfo
|
||||
# We can't import it from builtins or pytype crashes,
|
||||
# due to the fact that pytype uses a custom builtins stub rather than typeshed's builtins stub
|
||||
if sys.version_info >= (3, 10):
|
||||
_ClassInfo: TypeAlias = type | UnionType | tuple[_ClassInfo, ...]
|
||||
else:
|
||||
_ClassInfo: TypeAlias = type | tuple[_ClassInfo, ...]
|
||||
|
||||
class TestCase:
|
||||
failureException: type[BaseException]
|
||||
longMessage: bool
|
||||
|
||||
Reference in New Issue
Block a user