mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-08 21:14:48 +08:00
Use PEP 585 syntax in typing and typing_extensions, and remove module-level defaults where possible (#7036)
This commit is contained in:
@@ -10,12 +10,12 @@ Any = object()
|
||||
|
||||
class TypeVar:
|
||||
__name__: str
|
||||
__bound__: Type[Any] | None
|
||||
__constraints__: Tuple[Type[Any], ...]
|
||||
__bound__: type[Any] | None
|
||||
__constraints__: tuple[type[Any], ...]
|
||||
__covariant__: bool
|
||||
__contravariant__: bool
|
||||
def __init__(
|
||||
self, name: str, *constraints: Type[Any], bound: Type[Any] | None = ..., covariant: bool = ..., contravariant: bool = ...
|
||||
self, name: str, *constraints: type[Any], bound: type[Any] | None = ..., covariant: bool = ..., contravariant: bool = ...
|
||||
) -> None: ...
|
||||
|
||||
_promote = object()
|
||||
@@ -24,22 +24,22 @@ class _SpecialForm(object):
|
||||
def __getitem__(self, typeargs: Any) -> object: ...
|
||||
|
||||
Union: _SpecialForm = ...
|
||||
Optional: _SpecialForm = ...
|
||||
Tuple: _SpecialForm = ...
|
||||
Optional: _SpecialForm
|
||||
Tuple: _SpecialForm
|
||||
Generic: _SpecialForm = ...
|
||||
Protocol: _SpecialForm = ...
|
||||
Callable: _SpecialForm = ...
|
||||
Type: _SpecialForm = ...
|
||||
ClassVar: _SpecialForm = ...
|
||||
Final: _SpecialForm = ...
|
||||
Type: _SpecialForm
|
||||
ClassVar: _SpecialForm
|
||||
Final: _SpecialForm
|
||||
_F = TypeVar("_F", bound=Callable[..., Any])
|
||||
|
||||
def final(f: _F) -> _F: ...
|
||||
def overload(f: _F) -> _F: ...
|
||||
|
||||
Literal: _SpecialForm = ...
|
||||
Literal: _SpecialForm
|
||||
# TypedDict is a (non-subscriptable) special form.
|
||||
TypedDict: object = ...
|
||||
TypedDict: object
|
||||
|
||||
class GenericMeta(type): ...
|
||||
|
||||
@@ -58,7 +58,7 @@ _V_co = TypeVar("_V_co", covariant=True) # Any type covariant containers.
|
||||
_KT_co = TypeVar("_KT_co", covariant=True) # Key type covariant containers.
|
||||
_VT_co = TypeVar("_VT_co", covariant=True) # Value type covariant containers.
|
||||
_T_contra = TypeVar("_T_contra", contravariant=True) # Ditto contravariant.
|
||||
_TC = TypeVar("_TC", bound=Type[object])
|
||||
_TC = TypeVar("_TC", bound=type[object])
|
||||
|
||||
def no_type_check(f: _F) -> _F: ...
|
||||
def no_type_check_decorator(decorator: _F) -> _F: ...
|
||||
@@ -140,7 +140,7 @@ class Generator(Iterator[_T_co], Generic[_T_co, _T_contra, _V_co]):
|
||||
@overload
|
||||
@abstractmethod
|
||||
def throw(
|
||||
self, __typ: Type[BaseException], __val: BaseException | object = ..., __tb: TracebackType | None = ...
|
||||
self, __typ: type[BaseException], __val: BaseException | object = ..., __tb: TracebackType | None = ...
|
||||
) -> _T_co: ...
|
||||
@overload
|
||||
@abstractmethod
|
||||
@@ -240,10 +240,10 @@ class MutableSet(AbstractSet[_T], Generic[_T]):
|
||||
class MappingView(object):
|
||||
def __len__(self) -> int: ...
|
||||
|
||||
class ItemsView(MappingView, AbstractSet[Tuple[_KT_co, _VT_co]], Generic[_KT_co, _VT_co]):
|
||||
class ItemsView(MappingView, AbstractSet[tuple[_KT_co, _VT_co]], Generic[_KT_co, _VT_co]):
|
||||
def __init__(self, mapping: Mapping[_KT_co, _VT_co]) -> None: ...
|
||||
def __contains__(self, o: object) -> bool: ...
|
||||
def __iter__(self) -> Iterator[Tuple[_KT_co, _VT_co]]: ...
|
||||
def __iter__(self) -> Iterator[tuple[_KT_co, _VT_co]]: ...
|
||||
|
||||
class KeysView(MappingView, AbstractSet[_KT_co], Generic[_KT_co]):
|
||||
def __init__(self, mapping: Mapping[_KT_co, _VT_co]) -> None: ...
|
||||
@@ -259,7 +259,7 @@ class ValuesView(MappingView, Iterable[_VT_co], Generic[_VT_co]):
|
||||
class ContextManager(Protocol[_T_co]):
|
||||
def __enter__(self) -> _T_co: ...
|
||||
def __exit__(
|
||||
self, __exc_type: Type[BaseException] | None, __exc_value: BaseException | None, __traceback: TracebackType | None
|
||||
self, __exc_type: type[BaseException] | None, __exc_value: BaseException | None, __traceback: TracebackType | None
|
||||
) -> bool | None: ...
|
||||
|
||||
class Mapping(Iterable[_KT], Container[_KT], Generic[_KT, _VT_co]):
|
||||
@@ -274,10 +274,10 @@ class Mapping(Iterable[_KT], Container[_KT], Generic[_KT, _VT_co]):
|
||||
def get(self, k: _KT, default: _VT_co | _T) -> _VT_co | _T: ...
|
||||
def keys(self) -> list[_KT]: ...
|
||||
def values(self) -> list[_VT_co]: ...
|
||||
def items(self) -> list[Tuple[_KT, _VT_co]]: ...
|
||||
def items(self) -> list[tuple[_KT, _VT_co]]: ...
|
||||
def iterkeys(self) -> Iterator[_KT]: ...
|
||||
def itervalues(self) -> Iterator[_VT_co]: ...
|
||||
def iteritems(self) -> Iterator[Tuple[_KT, _VT_co]]: ...
|
||||
def iteritems(self) -> Iterator[tuple[_KT, _VT_co]]: ...
|
||||
def __contains__(self, o: object) -> bool: ...
|
||||
# Implement Sized (but don't have it as a base class).
|
||||
@abstractmethod
|
||||
@@ -293,12 +293,12 @@ class MutableMapping(Mapping[_KT, _VT], Generic[_KT, _VT]):
|
||||
def pop(self, k: _KT) -> _VT: ...
|
||||
@overload
|
||||
def pop(self, k: _KT, default: _VT | _T = ...) -> _VT | _T: ...
|
||||
def popitem(self) -> Tuple[_KT, _VT]: ...
|
||||
def popitem(self) -> tuple[_KT, _VT]: ...
|
||||
def setdefault(self, k: _KT, default: _VT = ...) -> _VT: ...
|
||||
@overload
|
||||
def update(self, __m: Mapping[_KT, _VT], **kwargs: _VT) -> None: ...
|
||||
@overload
|
||||
def update(self, __m: Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None: ...
|
||||
def update(self, __m: Iterable[tuple[_KT, _VT]], **kwargs: _VT) -> None: ...
|
||||
@overload
|
||||
def update(self, **kwargs: _VT) -> None: ...
|
||||
|
||||
@@ -355,7 +355,7 @@ class IO(Iterator[AnyStr], Generic[AnyStr]):
|
||||
def __enter__(self) -> IO[AnyStr]: ...
|
||||
@abstractmethod
|
||||
def __exit__(
|
||||
self, t: Type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
|
||||
self, t: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
|
||||
) -> bool | None: ...
|
||||
|
||||
class BinaryIO(IO[str]):
|
||||
@@ -404,16 +404,16 @@ class Match(Generic[AnyStr]):
|
||||
@overload
|
||||
def group(self, group1: str) -> AnyStr: ...
|
||||
@overload
|
||||
def group(self, group1: int, group2: int, *groups: int) -> Tuple[AnyStr, ...]: ...
|
||||
def group(self, group1: int, group2: int, *groups: int) -> tuple[AnyStr, ...]: ...
|
||||
@overload
|
||||
def group(self, group1: str, group2: str, *groups: str) -> Tuple[AnyStr, ...]: ...
|
||||
def groups(self, default: AnyStr = ...) -> Tuple[AnyStr, ...]: ...
|
||||
def group(self, group1: str, group2: str, *groups: str) -> tuple[AnyStr, ...]: ...
|
||||
def groups(self, default: AnyStr = ...) -> tuple[AnyStr, ...]: ...
|
||||
def groupdict(self, default: AnyStr = ...) -> Dict[str, AnyStr]: ...
|
||||
def start(self, __group: int | str = ...) -> int: ...
|
||||
def end(self, __group: int | str = ...) -> int: ...
|
||||
def span(self, __group: int | str = ...) -> Tuple[int, int]: ...
|
||||
def span(self, __group: int | str = ...) -> tuple[int, int]: ...
|
||||
@property
|
||||
def regs(self) -> Tuple[Tuple[int, int], ...]: ... # undocumented
|
||||
def regs(self) -> tuple[tuple[int, int], ...]: ... # undocumented
|
||||
|
||||
# We need a second TypeVar with the same definition as AnyStr, because
|
||||
# Pattern is generic over AnyStr (determining the type of its .pattern
|
||||
@@ -438,9 +438,9 @@ class Pattern(Generic[AnyStr]):
|
||||
@overload
|
||||
def sub(self, repl: Callable[[Match[_AnyStr2]], _AnyStr2], string: _AnyStr2, count: int = ...) -> _AnyStr2: ...
|
||||
@overload
|
||||
def subn(self, repl: _AnyStr2, string: _AnyStr2, count: int = ...) -> Tuple[_AnyStr2, int]: ...
|
||||
def subn(self, repl: _AnyStr2, string: _AnyStr2, count: int = ...) -> tuple[_AnyStr2, int]: ...
|
||||
@overload
|
||||
def subn(self, repl: Callable[[Match[_AnyStr2]], _AnyStr2], string: _AnyStr2, count: int = ...) -> Tuple[_AnyStr2, int]: ...
|
||||
def subn(self, repl: Callable[[Match[_AnyStr2]], _AnyStr2], string: _AnyStr2, count: int = ...) -> tuple[_AnyStr2, int]: ...
|
||||
|
||||
# Functions
|
||||
|
||||
@@ -448,7 +448,7 @@ def get_type_hints(
|
||||
obj: Callable[..., Any], globalns: Dict[Text, Any] | None = ..., localns: Dict[Text, Any] | None = ...
|
||||
) -> None: ...
|
||||
@overload
|
||||
def cast(tp: Type[_T], obj: Any) -> _T: ...
|
||||
def cast(tp: type[_T], obj: Any) -> _T: ...
|
||||
@overload
|
||||
def cast(tp: str, obj: Any) -> Any: ...
|
||||
@overload
|
||||
@@ -457,11 +457,11 @@ def cast(tp: object, obj: Any) -> Any: ...
|
||||
# Type constructors
|
||||
|
||||
# NamedTuple is special-cased in the type checker
|
||||
class NamedTuple(Tuple[Any, ...]):
|
||||
_fields: Tuple[str, ...]
|
||||
def __init__(self, typename: Text, fields: Iterable[Tuple[Text, Any]] = ..., **kwargs: Any) -> None: ...
|
||||
class NamedTuple(tuple[Any, ...]):
|
||||
_fields: tuple[str, ...]
|
||||
def __init__(self, typename: Text, fields: Iterable[tuple[Text, Any]] = ..., **kwargs: Any) -> None: ...
|
||||
@classmethod
|
||||
def _make(cls: Type[_T], iterable: Iterable[Any]) -> _T: ...
|
||||
def _make(cls: type[Self], iterable: Iterable[Any]) -> Self: ...
|
||||
def _asdict(self) -> Dict[str, Any]: ...
|
||||
def _replace(self: Self, **kwargs: Any) -> Self: ...
|
||||
|
||||
@@ -480,7 +480,7 @@ class _TypedDict(Mapping[str, object], metaclass=ABCMeta):
|
||||
def viewvalues(self) -> ValuesView[object]: ...
|
||||
def __delitem__(self, k: NoReturn) -> None: ...
|
||||
|
||||
def NewType(name: str, tp: Type[_T]) -> Type[_T]: ...
|
||||
def NewType(name: str, tp: type[_T]) -> type[_T]: ...
|
||||
|
||||
# This itself is only available during type checking
|
||||
def type_check_only(func_or_cls: _F) -> _F: ...
|
||||
|
||||
@@ -34,11 +34,11 @@ def runtime_checkable(cls: _TC) -> _TC: ...
|
||||
# This alias for above is kept here for backwards compatibility.
|
||||
runtime = runtime_checkable
|
||||
Protocol: _SpecialForm = ...
|
||||
Final: _SpecialForm = ...
|
||||
Final: _SpecialForm
|
||||
|
||||
def final(f: _F) -> _F: ...
|
||||
|
||||
Literal: _SpecialForm = ...
|
||||
Literal: _SpecialForm
|
||||
|
||||
def IntVar(name: str) -> Any: ... # returns a new TypeVar
|
||||
|
||||
@@ -58,7 +58,7 @@ class _TypedDict(Mapping[str, object], metaclass=abc.ABCMeta):
|
||||
def __delitem__(self, k: NoReturn) -> None: ...
|
||||
|
||||
# TypedDict is a (non-subscriptable) special form.
|
||||
TypedDict: object = ...
|
||||
TypedDict: object
|
||||
|
||||
OrderedDict = _Alias()
|
||||
|
||||
@@ -69,8 +69,8 @@ def get_type_hints(
|
||||
include_extras: bool = ...,
|
||||
) -> dict[str, Any]: ...
|
||||
|
||||
Annotated: _SpecialForm = ...
|
||||
_AnnotatedAlias: Any = ... # undocumented
|
||||
Annotated: _SpecialForm
|
||||
_AnnotatedAlias: Any # undocumented
|
||||
|
||||
@runtime_checkable
|
||||
class SupportsIndex(Protocol, metaclass=abc.ABCMeta):
|
||||
@@ -99,6 +99,6 @@ class ParamSpec:
|
||||
@property
|
||||
def kwargs(self) -> ParamSpecKwargs: ...
|
||||
|
||||
Concatenate: _SpecialForm = ...
|
||||
TypeAlias: _SpecialForm = ...
|
||||
TypeGuard: _SpecialForm = ...
|
||||
Concatenate: _SpecialForm
|
||||
TypeAlias: _SpecialForm
|
||||
TypeGuard: _SpecialForm
|
||||
|
||||
Reference in New Issue
Block a user