mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-02-05 01:17:39 +08:00
Use PEP 585 syntax in Python 2, protobuf & _ast stubs, where possible (#6949)
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import sys
|
||||
from _typeshed import Self
|
||||
from abc import ABCMeta
|
||||
from typing import Any, Dict, Iterator, List, Mapping, Type, TypeVar, Union
|
||||
from typing import Any, Iterator, Mapping, TypeVar, Union
|
||||
|
||||
_T = TypeVar("_T")
|
||||
_S = TypeVar("_S", bound=Type[Enum])
|
||||
_S = TypeVar("_S", bound=type[Enum])
|
||||
|
||||
# Note: EnumMeta actually subclasses type directly, not ABCMeta.
|
||||
# This is a temporary workaround to allow multiple creation of enums with builtins
|
||||
@@ -12,12 +12,12 @@ _S = TypeVar("_S", bound=Type[Enum])
|
||||
# spurious inconsistent metaclass structure. See #1595.
|
||||
# Structurally: Iterable[T], Reversible[T], Container[T] where T is the enum itself
|
||||
class EnumMeta(ABCMeta):
|
||||
def __iter__(self: Type[_T]) -> Iterator[_T]: ...
|
||||
def __reversed__(self: Type[_T]) -> Iterator[_T]: ...
|
||||
def __iter__(self: type[_T]) -> Iterator[_T]: ...
|
||||
def __reversed__(self: type[_T]) -> Iterator[_T]: ...
|
||||
def __contains__(self, member: object) -> bool: ...
|
||||
def __getitem__(self: Type[_T], name: str) -> _T: ...
|
||||
def __getitem__(self: type[_T], name: str) -> _T: ...
|
||||
@property
|
||||
def __members__(self: Type[_T]) -> Mapping[str, _T]: ...
|
||||
def __members__(self: type[_T]) -> Mapping[str, _T]: ...
|
||||
def __len__(self) -> int: ...
|
||||
|
||||
class Enum(metaclass=EnumMeta):
|
||||
@@ -25,21 +25,21 @@ class Enum(metaclass=EnumMeta):
|
||||
value: Any
|
||||
_name_: str
|
||||
_value_: Any
|
||||
_member_names_: List[str] # undocumented
|
||||
_member_map_: Dict[str, Enum] # undocumented
|
||||
_value2member_map_: Dict[int, Enum] # undocumented
|
||||
_member_names_: list[str] # undocumented
|
||||
_member_map_: dict[str, Enum] # undocumented
|
||||
_value2member_map_: dict[int, Enum] # undocumented
|
||||
if sys.version_info >= (3, 7):
|
||||
_ignore_: Union[str, List[str]]
|
||||
_ignore_: Union[str, list[str]]
|
||||
_order_: str
|
||||
__order__: str
|
||||
@classmethod
|
||||
def _missing_(cls, value: object) -> Any: ...
|
||||
@staticmethod
|
||||
def _generate_next_value_(name: str, start: int, count: int, last_values: List[Any]) -> Any: ...
|
||||
def __new__(cls: Type[_T], value: object) -> _T: ...
|
||||
def _generate_next_value_(name: str, start: int, count: int, last_values: list[Any]) -> Any: ...
|
||||
def __new__(cls: type[_T], value: object) -> _T: ...
|
||||
def __repr__(self) -> str: ...
|
||||
def __str__(self) -> str: ...
|
||||
def __dir__(self) -> List[str]: ...
|
||||
def __dir__(self) -> list[str]: ...
|
||||
def __format__(self, format_spec: str) -> str: ...
|
||||
def __hash__(self) -> Any: ...
|
||||
def __reduce_ex__(self, proto: object) -> Any: ...
|
||||
|
||||
@@ -3,7 +3,7 @@ from _typeshed import Self
|
||||
from abc import abstractmethod
|
||||
from logging import Logger
|
||||
from types import TracebackType
|
||||
from typing import Any, Callable, Container, Generic, Iterable, Iterator, List, Optional, Protocol, Set, Tuple, TypeVar
|
||||
from typing import Any, Callable, Container, Generic, Iterable, Iterator, Optional, Protocol, TypeVar
|
||||
|
||||
FIRST_COMPLETED: str
|
||||
FIRST_EXCEPTION: str
|
||||
@@ -41,7 +41,7 @@ class Future(Generic[_T]):
|
||||
def set_running_or_notify_cancel(self) -> bool: ...
|
||||
def set_result(self, result: _T) -> None: ...
|
||||
def exception(self, timeout: Optional[float] = ...) -> Any: ...
|
||||
def exception_info(self, timeout: Optional[float] = ...) -> Tuple[Any, Optional[TracebackType]]: ...
|
||||
def exception_info(self, timeout: Optional[float] = ...) -> tuple[Any, Optional[TracebackType]]: ...
|
||||
def set_exception(self, exception: Any) -> None: ...
|
||||
def set_exception_info(self, exception: Any, traceback: Optional[TracebackType]) -> None: ...
|
||||
|
||||
@@ -55,11 +55,11 @@ class Executor:
|
||||
def as_completed(fs: Iterable[Future[_T]], timeout: Optional[float] = ...) -> Iterator[Future[_T]]: ...
|
||||
def wait(
|
||||
fs: _Collection[Future[_T]], timeout: Optional[float] = ..., return_when: str = ...
|
||||
) -> Tuple[Set[Future[_T]], Set[Future[_T]]]: ...
|
||||
) -> tuple[set[Future[_T]], set[Future[_T]]]: ...
|
||||
|
||||
class _Waiter:
|
||||
event: threading.Event
|
||||
finished_futures: List[Future[Any]]
|
||||
finished_futures: list[Future[Any]]
|
||||
def __init__(self) -> None: ...
|
||||
def add_result(self, future: Future[Any]) -> None: ...
|
||||
def add_exception(self, future: Future[Any]) -> None: ...
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from _typeshed import Self
|
||||
from typing import Any, Container, Generic, Iterable, Iterator, Optional, SupportsInt, Text, Tuple, TypeVar, overload
|
||||
from typing import Any, Container, Generic, Iterable, Iterator, Optional, SupportsInt, Text, TypeVar, overload
|
||||
|
||||
# Undocumented length constants
|
||||
IPV4LENGTH: int
|
||||
@@ -123,7 +123,7 @@ class IPv6Address(_BaseAddress):
|
||||
@property
|
||||
def sixtofour(self) -> Optional[IPv4Address]: ...
|
||||
@property
|
||||
def teredo(self) -> Optional[Tuple[IPv4Address, IPv4Address]]: ...
|
||||
def teredo(self) -> Optional[tuple[IPv4Address, IPv4Address]]: ...
|
||||
|
||||
class IPv6Network(_BaseNetwork[IPv6Address]):
|
||||
@property
|
||||
@@ -139,11 +139,11 @@ def summarize_address_range(first: IPv4Address, last: IPv4Address) -> Iterator[I
|
||||
def summarize_address_range(first: IPv6Address, last: IPv6Address) -> Iterator[IPv6Network]: ...
|
||||
def collapse_addresses(addresses: Iterable[_N]) -> Iterator[_N]: ...
|
||||
@overload
|
||||
def get_mixed_type_key(obj: _A) -> Tuple[int, _A]: ...
|
||||
def get_mixed_type_key(obj: _A) -> tuple[int, _A]: ...
|
||||
@overload
|
||||
def get_mixed_type_key(obj: IPv4Network) -> Tuple[int, IPv4Address, IPv4Address]: ...
|
||||
def get_mixed_type_key(obj: IPv4Network) -> tuple[int, IPv4Address, IPv4Address]: ...
|
||||
@overload
|
||||
def get_mixed_type_key(obj: IPv6Network) -> Tuple[int, IPv6Address, IPv6Address]: ...
|
||||
def get_mixed_type_key(obj: IPv6Network) -> tuple[int, IPv6Address, IPv6Address]: ...
|
||||
|
||||
class AddressValueError(ValueError): ...
|
||||
class NetmaskValueError(ValueError): ...
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from collections.abc import MutableMapping
|
||||
from typing import Any, Callable, Iterable, Iterator, List, Optional, Sequence, Text, TypeVar, Union, overload
|
||||
from typing import Any, Callable, Iterable, Iterator, Optional, Sequence, Text, TypeVar, Union, overload
|
||||
from typing_extensions import SupportsIndex
|
||||
|
||||
from google.protobuf.descriptor import Descriptor
|
||||
@@ -23,7 +23,7 @@ class BaseContainer(Sequence[_T]):
|
||||
@overload
|
||||
def __getitem__(self, key: SupportsIndex) -> _T: ...
|
||||
@overload
|
||||
def __getitem__(self, key: slice) -> List[_T]: ...
|
||||
def __getitem__(self, key: slice) -> list[_T]: ...
|
||||
|
||||
class RepeatedScalarFieldContainer(BaseContainer[_ScalarV]):
|
||||
def __init__(self, message_listener: MessageListener, message_descriptor: Descriptor) -> None: ...
|
||||
@@ -37,7 +37,7 @@ class RepeatedScalarFieldContainer(BaseContainer[_ScalarV]):
|
||||
def __setitem__(self, key: int, value: _ScalarV) -> None: ...
|
||||
@overload
|
||||
def __setitem__(self, key: slice, value: Iterable[_ScalarV]) -> None: ...
|
||||
def __getslice__(self, start: int, stop: int) -> List[_ScalarV]: ...
|
||||
def __getslice__(self, start: int, stop: int) -> list[_ScalarV]: ...
|
||||
def __setslice__(self, start: int, stop: int, values: Iterable[_ScalarV]) -> None: ...
|
||||
def __delitem__(self, key: Union[int, slice]) -> None: ...
|
||||
def __delslice__(self, start: int, stop: int) -> None: ...
|
||||
@@ -52,7 +52,7 @@ class RepeatedCompositeFieldContainer(BaseContainer[_MessageV]):
|
||||
def MergeFrom(self: _M, other: _M) -> None: ...
|
||||
def remove(self, elem: _MessageV) -> None: ...
|
||||
def pop(self, key: int = ...) -> _MessageV: ...
|
||||
def __getslice__(self, start: int, stop: int) -> List[_MessageV]: ...
|
||||
def __getslice__(self, start: int, stop: int) -> list[_MessageV]: ...
|
||||
def __delitem__(self, key: Union[int, slice]) -> None: ...
|
||||
def __delslice__(self, start: int, stop: int) -> None: ...
|
||||
def __eq__(self, other: object) -> bool: ...
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Generic, List, Text, Tuple, TypeVar
|
||||
from typing import Generic, Text, TypeVar
|
||||
|
||||
from google.protobuf.descriptor import EnumDescriptor
|
||||
|
||||
@@ -11,8 +11,8 @@ class _EnumTypeWrapper(Generic[_V]):
|
||||
def __init__(self, enum_type: EnumDescriptor) -> None: ...
|
||||
def Name(self, number: _V) -> str: ...
|
||||
def Value(self, name: Text | bytes) -> _V: ...
|
||||
def keys(self) -> List[str]: ...
|
||||
def values(self) -> List[_V]: ...
|
||||
def items(self) -> List[Tuple[str, _V]]: ...
|
||||
def keys(self) -> list[str]: ...
|
||||
def values(self) -> list[_V]: ...
|
||||
def items(self) -> list[tuple[str, _V]]: ...
|
||||
|
||||
class EnumTypeWrapper(_EnumTypeWrapper[int]): ...
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Any as tAny, Dict, Optional, Type
|
||||
from typing import Any as tAny, Optional
|
||||
|
||||
class Error(Exception): ...
|
||||
class ParseError(Error): ...
|
||||
@@ -91,4 +91,4 @@ class ListValue:
|
||||
def add_struct(self): ...
|
||||
def add_list(self): ...
|
||||
|
||||
WKTBASES: Dict[str, Type[tAny]]
|
||||
WKTBASES: dict[str, type[tAny]]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Any, Dict, Optional, Text, TypeVar, Union
|
||||
from typing import Any, Optional, Text, TypeVar, Union
|
||||
|
||||
from google.protobuf.descriptor_pool import DescriptorPool
|
||||
from google.protobuf.message import Message
|
||||
@@ -26,7 +26,7 @@ def MessageToDict(
|
||||
use_integers_for_enums: bool = ...,
|
||||
descriptor_pool: Optional[DescriptorPool] = ...,
|
||||
float_precision: Optional[int] = ...,
|
||||
) -> Dict[Text, Any]: ...
|
||||
) -> dict[Text, Any]: ...
|
||||
def Parse(
|
||||
text: Union[bytes, Text],
|
||||
message: _MessageT,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Any, Sequence, Tuple, Type, TypeVar
|
||||
from typing import Any, Sequence, TypeVar
|
||||
|
||||
from .descriptor import Descriptor, FieldDescriptor
|
||||
from .internal.extension_dict import _ExtensionDict, _ExtensionFieldDescriptor
|
||||
@@ -23,12 +23,12 @@ class Message:
|
||||
def ParseFromString(self, serialized: bytes) -> int: ...
|
||||
def SerializeToString(self, deterministic: bool = ...) -> bytes: ...
|
||||
def SerializePartialToString(self, deterministic: bool = ...) -> bytes: ...
|
||||
def ListFields(self) -> Sequence[Tuple[FieldDescriptor, Any]]: ...
|
||||
def ListFields(self) -> Sequence[tuple[FieldDescriptor, Any]]: ...
|
||||
def HasExtension(self: _M, extension_handle: _ExtensionFieldDescriptor[_M, Any]) -> bool: ...
|
||||
def ClearExtension(self: _M, extension_handle: _ExtensionFieldDescriptor[_M, Any]) -> None: ...
|
||||
def ByteSize(self) -> int: ...
|
||||
@classmethod
|
||||
def FromString(cls: Type[_M], s: bytes) -> _M: ...
|
||||
def FromString(cls: type[_M], s: bytes) -> _M: ...
|
||||
@property
|
||||
def Extensions(self: _M) -> _ExtensionDict[_M]: ...
|
||||
# Intentionally left out typing on these three methods, because they are
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Any, Dict, Iterable, Optional, Type
|
||||
from typing import Any, Iterable, Optional
|
||||
|
||||
from google.protobuf.descriptor import Descriptor
|
||||
from google.protobuf.descriptor_pb2 import FileDescriptorProto
|
||||
@@ -8,7 +8,7 @@ from google.protobuf.message import Message
|
||||
class MessageFactory:
|
||||
pool: Any
|
||||
def __init__(self, pool: Optional[DescriptorPool] = ...) -> None: ...
|
||||
def GetPrototype(self, descriptor: Descriptor) -> Type[Message]: ...
|
||||
def GetMessages(self, files: Iterable[str]) -> Dict[str, Type[Message]]: ...
|
||||
def GetPrototype(self, descriptor: Descriptor) -> type[Message]: ...
|
||||
def GetMessages(self, files: Iterable[str]) -> dict[str, type[Message]]: ...
|
||||
|
||||
def GetMessages(file_protos: Iterable[FileDescriptorProto]) -> Dict[str, Type[Message]]: ...
|
||||
def GetMessages(file_protos: Iterable[FileDescriptorProto]) -> dict[str, type[Message]]: ...
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from concurrent.futures import Future
|
||||
from typing import Callable, Optional, Text, Type
|
||||
from typing import Callable, Optional, Text
|
||||
|
||||
from google.protobuf.descriptor import MethodDescriptor, ServiceDescriptor
|
||||
from google.protobuf.message import Message
|
||||
@@ -16,8 +16,8 @@ class Service:
|
||||
request: Message,
|
||||
done: Optional[Callable[[Message], None]],
|
||||
) -> Optional[Future[Message]]: ...
|
||||
def GetRequestClass(self, method_descriptor: MethodDescriptor) -> Type[Message]: ...
|
||||
def GetResponseClass(self, method_descriptor: MethodDescriptor) -> Type[Message]: ...
|
||||
def GetRequestClass(self, method_descriptor: MethodDescriptor) -> type[Message]: ...
|
||||
def GetResponseClass(self, method_descriptor: MethodDescriptor) -> type[Message]: ...
|
||||
|
||||
class RpcController:
|
||||
def Reset(self) -> None: ...
|
||||
@@ -34,6 +34,6 @@ class RpcChannel:
|
||||
method_descriptor: MethodDescriptor,
|
||||
rpc_controller: RpcController,
|
||||
request: Message,
|
||||
response_class: Type[Message],
|
||||
response_class: type[Message],
|
||||
done: Optional[Callable[[Message], None]],
|
||||
) -> Optional[Future[Message]]: ...
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
from typing import Dict, Iterable, Type, Union
|
||||
from typing import Iterable, Union
|
||||
|
||||
from google.protobuf.descriptor import Descriptor, EnumDescriptor, FileDescriptor, ServiceDescriptor
|
||||
from google.protobuf.message import Message
|
||||
from google.protobuf.message_factory import MessageFactory
|
||||
|
||||
class SymbolDatabase(MessageFactory):
|
||||
def RegisterMessage(self, message: Union[Type[Message], Message]) -> Union[Type[Message], Message]: ...
|
||||
def RegisterMessage(self, message: Union[type[Message], Message]) -> Union[type[Message], Message]: ...
|
||||
def RegisterMessageDescriptor(self, message_descriptor: Descriptor) -> None: ...
|
||||
def RegisterEnumDescriptor(self, enum_descriptor: EnumDescriptor) -> EnumDescriptor: ...
|
||||
def RegisterServiceDescriptor(self, service_descriptor: ServiceDescriptor) -> None: ...
|
||||
def RegisterFileDescriptor(self, file_descriptor: FileDescriptor) -> None: ...
|
||||
def GetSymbol(self, symbol: str) -> Type[Message]: ...
|
||||
def GetMessages(self, files: Iterable[str]) -> Dict[str, Type[Message]]: ...
|
||||
def GetSymbol(self, symbol: str) -> type[Message]: ...
|
||||
def GetMessages(self, files: Iterable[str]) -> dict[str, type[Message]]: ...
|
||||
|
||||
def Default(): ...
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from _typeshed import SupportsWrite
|
||||
from typing import Any, Callable, Iterable, Optional, Text, Tuple, TypeVar, Union
|
||||
from typing import Any, Callable, Iterable, Optional, Text, TypeVar, Union
|
||||
|
||||
from .descriptor import FieldDescriptor
|
||||
from .descriptor_pool import DescriptorPool
|
||||
@@ -190,7 +190,7 @@ class Tokenizer:
|
||||
def TryConsume(self, token: str) -> bool: ...
|
||||
def Consume(self, token: str) -> None: ...
|
||||
def ConsumeComment(self) -> str: ...
|
||||
def ConsumeCommentOrTrailingComment(self) -> Tuple[bool, str]: ...
|
||||
def ConsumeCommentOrTrailingComment(self) -> tuple[bool, str]: ...
|
||||
def TryConsumeIdentifier(self) -> bool: ...
|
||||
def ConsumeIdentifier(self) -> str: ...
|
||||
def TryConsumeIdentifierOrNumber(self) -> bool: ...
|
||||
|
||||
@@ -17,8 +17,6 @@ from typing import (
|
||||
NoReturn,
|
||||
Pattern,
|
||||
Text,
|
||||
Tuple,
|
||||
Type,
|
||||
TypeVar,
|
||||
ValuesView,
|
||||
overload,
|
||||
@@ -40,11 +38,11 @@ PY2: Literal[True]
|
||||
PY3: Literal[False]
|
||||
PY34: Literal[False]
|
||||
|
||||
string_types: tuple[Type[str], Type[unicode]]
|
||||
integer_types: tuple[Type[int], Type[long]]
|
||||
class_types: tuple[Type[Type[Any]], Type[types.ClassType]]
|
||||
text_type: Type[unicode]
|
||||
binary_type: Type[str]
|
||||
string_types: tuple[type[str], type[unicode]]
|
||||
integer_types: tuple[type[int], type[long]]
|
||||
class_types: tuple[type[type[Any]], type[types.ClassType]]
|
||||
text_type: type[unicode]
|
||||
binary_type: type[str]
|
||||
|
||||
MAXSIZE: int
|
||||
|
||||
@@ -62,9 +60,9 @@ class Iterator:
|
||||
|
||||
def get_method_function(meth: types.MethodType) -> types.FunctionType: ...
|
||||
def get_method_self(meth: types.MethodType) -> object | None: ...
|
||||
def get_function_closure(fun: types.FunctionType) -> Tuple[types._Cell, ...] | None: ...
|
||||
def get_function_closure(fun: types.FunctionType) -> tuple[types._Cell, ...] | None: ...
|
||||
def get_function_code(fun: types.FunctionType) -> types.CodeType: ...
|
||||
def get_function_defaults(fun: types.FunctionType) -> Tuple[Any, ...] | None: ...
|
||||
def get_function_defaults(fun: types.FunctionType) -> tuple[Any, ...] | None: ...
|
||||
def get_function_globals(fun: types.FunctionType) -> dict[str, Any]: ...
|
||||
def iterkeys(d: Mapping[_K, _V]) -> typing.Iterator[_K]: ...
|
||||
def itervalues(d: Mapping[_K, _V]) -> typing.Iterator[_V]: ...
|
||||
@@ -89,9 +87,9 @@ def assertRaisesRegex(self: unittest.TestCase, msg: str = ...) -> Any: ...
|
||||
@overload
|
||||
def assertRaisesRegex(self: unittest.TestCase, callable_obj: Callable[..., Any], *args: Any, **kwargs: Any) -> Any: ...
|
||||
def assertRegex(self: unittest.TestCase, text: AnyStr, expected_regex: AnyStr | Pattern[AnyStr], msg: str = ...) -> None: ...
|
||||
def reraise(tp: Type[BaseException] | None, value: BaseException | None, tb: types.TracebackType | None = ...) -> NoReturn: ...
|
||||
def reraise(tp: type[BaseException] | None, value: BaseException | None, tb: types.TracebackType | None = ...) -> NoReturn: ...
|
||||
def exec_(_code_: unicode | types.CodeType, _globs_: dict[str, Any] = ..., _locs_: dict[str, Any] = ...): ...
|
||||
def raise_from(value: BaseException | Type[BaseException], from_value: BaseException | None) -> NoReturn: ...
|
||||
def raise_from(value: BaseException | type[BaseException], from_value: BaseException | None) -> NoReturn: ...
|
||||
|
||||
print_ = print
|
||||
|
||||
@@ -105,7 +103,7 @@ def python_2_unicode_compatible(klass: _T) -> _T: ...
|
||||
class _LazyDescr(object):
|
||||
name: str
|
||||
def __init__(self, name: str) -> None: ...
|
||||
def __get__(self, obj: object | None, type: Type[Any] | None = ...) -> Any: ...
|
||||
def __get__(self, obj: object | None, type: type[Any] | None = ...) -> Any: ...
|
||||
|
||||
class MovedModule(_LazyDescr):
|
||||
mod: str
|
||||
|
||||
Reference in New Issue
Block a user