Use PEP 604 syntax in non-autogenerated protobuf stubs (#7506)

This commit is contained in:
Alex Waygood
2022-03-17 11:34:31 +00:00
committed by GitHub
parent 061ddad8e3
commit e8286e7048
9 changed files with 74 additions and 77 deletions

View File

@@ -1,8 +1,8 @@
from typing import Any, Optional
from typing import Any
class DescriptorPool:
def __new__(cls, descriptor_db: Optional[Any] = ...): ...
def __init__(self, descriptor_db: Optional[Any] = ...) -> None: ...
def __new__(cls, descriptor_db: Any | None = ...): ...
def __init__(self, descriptor_db: Any | None = ...) -> None: ...
def Add(self, file_desc_proto): ...
def AddSerializedFile(self, serialized_file_desc_proto): ...
def AddDescriptor(self, desc): ...

View File

@@ -1,5 +1,5 @@
from collections.abc import MutableMapping
from typing import Any, Callable, Iterable, Iterator, Optional, Sequence, Text, TypeVar, Union, overload
from typing import Any, Callable, Iterable, Iterator, Sequence, Text, TypeVar, overload
from typing_extensions import SupportsIndex
from google.protobuf.descriptor import Descriptor
@@ -9,8 +9,8 @@ from google.protobuf.internal.type_checkers import _ValueChecker
from google.protobuf.message import Message
_T = TypeVar("_T")
_K = TypeVar("_K", bound=Union[bool, int, Text])
_ScalarV = TypeVar("_ScalarV", bound=Union[bool, int, float, Text, bytes])
_K = TypeVar("_K", bound=bool | int | Text)
_ScalarV = TypeVar("_ScalarV", bound=bool | int | float | Text | bytes)
_MessageV = TypeVar("_MessageV", bound=Message)
_M = TypeVar("_M")
@@ -19,7 +19,7 @@ class BaseContainer(Sequence[_T]):
def __len__(self) -> int: ...
def __ne__(self, other: object) -> bool: ...
def __hash__(self) -> int: ...
def sort(self, *, key: Optional[Callable[[_T], Any]] = ..., reverse: bool = ...) -> None: ...
def sort(self, *, key: Callable[[_T], Any] | None = ..., reverse: bool = ...) -> None: ...
@overload
def __getitem__(self, key: SupportsIndex) -> _T: ...
@overload
@@ -29,7 +29,7 @@ class RepeatedScalarFieldContainer(BaseContainer[_ScalarV]):
def __init__(self, message_listener: MessageListener, type_checker: _ValueChecker[_ScalarV]) -> None: ...
def append(self, value: _ScalarV) -> None: ...
def insert(self, key: int, value: _ScalarV) -> None: ...
def extend(self, elem_seq: Optional[Iterable[_ScalarV]]) -> None: ...
def extend(self, elem_seq: Iterable[_ScalarV] | None) -> None: ...
def MergeFrom(self: _M, other: _M) -> None: ...
def remove(self, elem: _ScalarV) -> None: ...
def pop(self, key: int = ...) -> _ScalarV: ...
@@ -39,7 +39,7 @@ class RepeatedScalarFieldContainer(BaseContainer[_ScalarV]):
def __setitem__(self, key: slice, value: Iterable[_ScalarV]) -> None: ...
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 __delitem__(self, key: int | slice) -> None: ...
def __delslice__(self, start: int, stop: int) -> None: ...
def __eq__(self, other: object) -> bool: ...
@@ -53,7 +53,7 @@ class RepeatedCompositeFieldContainer(BaseContainer[_MessageV]):
def remove(self, elem: _MessageV) -> None: ...
def pop(self, key: int = ...) -> _MessageV: ...
def __getslice__(self, start: int, stop: int) -> list[_MessageV]: ...
def __delitem__(self, key: Union[int, slice]) -> None: ...
def __delitem__(self, key: int | slice) -> None: ...
def __delslice__(self, start: int, stop: int) -> None: ...
def __eq__(self, other: object) -> bool: ...
@@ -74,7 +74,7 @@ class ScalarMap(MutableMapping[_K, _ScalarV]):
@overload
def get(self, key: _K, default: None = ...) -> _ScalarV: ...
@overload
def get(self, key: _K, default: Union[_ScalarV, _T]) -> Union[_ScalarV, _T]: ...
def get(self, key: _K, default: _ScalarV | _T) -> _ScalarV | _T: ...
def MergeFrom(self: _M, other: _M): ...
def InvalidateIterators(self) -> None: ...
def GetEntryClass(self) -> GeneratedProtocolMessageType: ...
@@ -96,7 +96,7 @@ class MessageMap(MutableMapping[_K, _MessageV]):
@overload
def get(self, key: _K, default: None = ...) -> _MessageV: ...
@overload
def get(self, key: _K, default: Union[_MessageV, _T]) -> Union[_MessageV, _T]: ...
def get(self, key: _K, default: _MessageV | _T) -> _MessageV | _T: ...
def get_or_create(self, key: _K) -> _MessageV: ...
def MergeFrom(self: _M, other: _M): ...
def InvalidateIterators(self) -> None: ...

View File

@@ -1,4 +1,4 @@
from typing import Any, Generic, Iterator, Text, TypeVar, Union
from typing import Any, Generic, Iterator, Text, TypeVar
from google.protobuf.descriptor import FieldDescriptor
from google.protobuf.internal.containers import RepeatedCompositeFieldContainer, RepeatedScalarFieldContainer
@@ -7,7 +7,7 @@ from google.protobuf.message import Message
_ContainerMessageT = TypeVar("_ContainerMessageT", bound=Message)
_ExtenderMessageT = TypeVar(
"_ExtenderMessageT",
bound=Union[Message, RepeatedScalarFieldContainer[Any], RepeatedCompositeFieldContainer[Any], bool, int, float, Text, bytes],
bound=Message | RepeatedScalarFieldContainer[Any] | RepeatedCompositeFieldContainer[Any] | bool | int | float | Text | bytes,
)
class _ExtensionFieldDescriptor(FieldDescriptor, Generic[_ContainerMessageT, _ExtenderMessageT]): ...

View File

@@ -1,10 +1,10 @@
from datetime import datetime, timedelta
from typing import Any as tAny, Optional
from typing import Any as tAny
class Any:
type_url: tAny = ...
value: tAny = ...
def Pack(self, msg: tAny, type_url_prefix: str = ..., deterministic: Optional[tAny] = ...) -> None: ...
def Pack(self, msg: tAny, type_url_prefix: str = ..., deterministic: tAny | None = ...) -> None: ...
def Unpack(self, msg: tAny): ...
def TypeName(self): ...
def Is(self, descriptor: tAny): ...
@@ -55,7 +55,7 @@ class FieldMask:
) -> None: ...
class _FieldMaskTree:
def __init__(self, field_mask: Optional[tAny] = ...) -> None: ...
def __init__(self, field_mask: tAny | None = ...) -> None: ...
def MergeFromFieldMask(self, field_mask: tAny) -> None: ...
def AddPath(self, path: tAny): ...
def ToFieldMask(self, field_mask: tAny) -> None: ...

View File

@@ -1,4 +1,4 @@
from typing import Any, Optional, Text, TypeVar, Union
from typing import Any, Text, TypeVar
from google.protobuf.descriptor_pool import DescriptorPool
from google.protobuf.message import Message
@@ -16,23 +16,20 @@ def MessageToJson(
indent: int = ...,
sort_keys: bool = ...,
use_integers_for_enums: bool = ...,
descriptor_pool: Optional[DescriptorPool] = ...,
float_precision: Optional[int] = ...,
descriptor_pool: DescriptorPool | None = ...,
float_precision: int | None = ...,
) -> str: ...
def MessageToDict(
message: Message,
including_default_value_fields: bool = ...,
preserving_proto_field_name: bool = ...,
use_integers_for_enums: bool = ...,
descriptor_pool: Optional[DescriptorPool] = ...,
float_precision: Optional[int] = ...,
descriptor_pool: DescriptorPool | None = ...,
float_precision: int | None = ...,
) -> dict[Text, Any]: ...
def Parse(
text: Union[bytes, Text],
message: _MessageT,
ignore_unknown_fields: bool = ...,
descriptor_pool: Optional[DescriptorPool] = ...,
text: bytes | Text, message: _MessageT, ignore_unknown_fields: bool = ..., descriptor_pool: DescriptorPool | None = ...
) -> _MessageT: ...
def ParseDict(
js_dict: Any, message: _MessageT, ignore_unknown_fields: bool = ..., descriptor_pool: Optional[DescriptorPool] = ...
js_dict: Any, message: _MessageT, ignore_unknown_fields: bool = ..., descriptor_pool: DescriptorPool | None = ...
) -> _MessageT: ...

View File

@@ -1,4 +1,4 @@
from typing import Any, Iterable, Optional
from typing import Any, Iterable
from google.protobuf.descriptor import Descriptor
from google.protobuf.descriptor_pb2 import FileDescriptorProto
@@ -7,7 +7,7 @@ from google.protobuf.message import Message
class MessageFactory:
pool: Any
def __init__(self, pool: Optional[DescriptorPool] = ...) -> None: ...
def __init__(self, pool: DescriptorPool | None = ...) -> None: ...
def GetPrototype(self, descriptor: Descriptor) -> type[Message]: ...
def GetMessages(self, files: Iterable[str]) -> dict[str, type[Message]]: ...

View File

@@ -1,5 +1,5 @@
from concurrent.futures import Future
from typing import Callable, Optional, Text
from typing import Callable, Text
from google.protobuf.descriptor import MethodDescriptor, ServiceDescriptor
from google.protobuf.message import Message
@@ -14,15 +14,15 @@ class Service:
method_descriptor: MethodDescriptor,
rpc_controller: RpcController,
request: Message,
done: Optional[Callable[[Message], None]],
) -> Optional[Future[Message]]: ...
done: Callable[[Message], None] | None,
) -> Future[Message] | None: ...
def GetRequestClass(self, method_descriptor: MethodDescriptor) -> type[Message]: ...
def GetResponseClass(self, method_descriptor: MethodDescriptor) -> type[Message]: ...
class RpcController:
def Reset(self) -> None: ...
def Failed(self) -> bool: ...
def ErrorText(self) -> Optional[Text]: ...
def ErrorText(self) -> Text | None: ...
def StartCancel(self) -> None: ...
def SetFailed(self, reason: Text) -> None: ...
def IsCanceled(self) -> bool: ...
@@ -35,5 +35,5 @@ class RpcChannel:
rpc_controller: RpcController,
request: Message,
response_class: type[Message],
done: Optional[Callable[[Message], None]],
) -> Optional[Future[Message]]: ...
done: Callable[[Message], None] | None,
) -> Future[Message] | None: ...

View File

@@ -1,11 +1,11 @@
from typing import Iterable, Union
from typing import Iterable
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: type[Message] | Message) -> type[Message] | Message: ...
def RegisterMessageDescriptor(self, message_descriptor: Descriptor) -> None: ...
def RegisterEnumDescriptor(self, enum_descriptor: EnumDescriptor) -> EnumDescriptor: ...
def RegisterServiceDescriptor(self, service_descriptor: ServiceDescriptor) -> None: ...

View File

@@ -1,5 +1,5 @@
from _typeshed import SupportsWrite
from typing import Any, Callable, Iterable, Optional, Text, TypeVar, Union
from typing import Any, Callable, Iterable, Text, TypeVar
from .descriptor import FieldDescriptor
from .descriptor_pool import DescriptorPool
@@ -10,9 +10,9 @@ _M = TypeVar("_M", bound=Message) # message type (of self)
class Error(Exception): ...
class ParseError(Error):
def __init__(self, message: Optional[str] = ..., line: Optional[int] = ..., column: Optional[int] = ...) -> None: ...
def GetLine(self) -> Optional[int]: ...
def GetColumn(self) -> Optional[int]: ...
def __init__(self, message: str | None = ..., line: int | None = ..., column: int | None = ...) -> None: ...
def GetLine(self) -> int | None: ...
def GetColumn(self) -> int | None: ...
class TextWriter:
def __init__(self, as_utf8: bool) -> None: ...
@@ -20,7 +20,7 @@ class TextWriter:
def getvalue(self) -> str: ...
def close(self) -> None: ...
_MessageFormatter = Callable[[Message, int, bool], Optional[Text]]
_MessageFormatter = Callable[[Message, int, bool], Text | None]
def MessageToString(
message: Message,
@@ -29,12 +29,12 @@ def MessageToString(
use_short_repeated_primitives: bool = ...,
pointy_brackets: bool = ...,
use_index_order: bool = ...,
float_format: Optional[str] = ...,
double_format: Optional[str] = ...,
float_format: str | None = ...,
double_format: str | None = ...,
use_field_number: bool = ...,
descriptor_pool: Optional[DescriptorPool] = ...,
descriptor_pool: DescriptorPool | None = ...,
indent: int = ...,
message_formatter: Optional[_MessageFormatter] = ...,
message_formatter: _MessageFormatter | None = ...,
print_unknown_fields: bool = ...,
force_colon: bool = ...,
) -> str: ...
@@ -45,10 +45,10 @@ def MessageToBytes(
use_short_repeated_primitives: bool = ...,
pointy_brackets: bool = ...,
use_index_order: bool = ...,
float_format: Optional[str] = ...,
double_format: Optional[str] = ...,
float_format: str | None = ...,
double_format: str | None = ...,
use_field_number: bool = ...,
descriptor_pool: Optional[DescriptorPool] = ...,
descriptor_pool: DescriptorPool | None = ...,
indent: int = ...,
message_formatter: _MessageFormatter = ...,
print_unknown_fields: bool = ...,
@@ -63,11 +63,11 @@ def PrintMessage(
use_short_repeated_primitives: bool = ...,
pointy_brackets: bool = ...,
use_index_order: bool = ...,
float_format: Optional[str] = ...,
double_format: Optional[str] = ...,
float_format: str | None = ...,
double_format: str | None = ...,
use_field_number: bool = ...,
descriptor_pool: Optional[DescriptorPool] = ...,
message_formatter: Optional[_MessageFormatter] = ...,
descriptor_pool: DescriptorPool | None = ...,
message_formatter: _MessageFormatter | None = ...,
print_unknown_fields: bool = ...,
force_colon: bool = ...,
) -> None: ...
@@ -81,9 +81,9 @@ def PrintField(
use_short_repeated_primitives: bool = ...,
pointy_brackets: bool = ...,
use_index_order: bool = ...,
float_format: Optional[str] = ...,
double_format: Optional[str] = ...,
message_formatter: Optional[_MessageFormatter] = ...,
float_format: str | None = ...,
double_format: str | None = ...,
message_formatter: _MessageFormatter | None = ...,
print_unknown_fields: bool = ...,
force_colon: bool = ...,
) -> None: ...
@@ -97,9 +97,9 @@ def PrintFieldValue(
use_short_repeated_primitives: bool = ...,
pointy_brackets: bool = ...,
use_index_order: bool = ...,
float_format: Optional[str] = ...,
double_format: Optional[str] = ...,
message_formatter: Optional[_MessageFormatter] = ...,
float_format: str | None = ...,
double_format: str | None = ...,
message_formatter: _MessageFormatter | None = ...,
print_unknown_fields: bool = ...,
force_colon: bool = ...,
) -> None: ...
@@ -112,11 +112,11 @@ class _Printer:
use_short_repeated_primitives: bool = ...
pointy_brackets: bool = ...
use_index_order: bool = ...
float_format: Optional[str] = ...
double_format: Optional[str] = ...
float_format: str | None = ...
double_format: str | None = ...
use_field_number: bool = ...
descriptor_pool: Optional[DescriptorPool] = ...
message_formatter: Optional[_MessageFormatter] = ...
descriptor_pool: DescriptorPool | None = ...
message_formatter: _MessageFormatter | None = ...
print_unknown_fields: bool = ...
force_colon: bool = ...
def __init__(
@@ -128,11 +128,11 @@ class _Printer:
use_short_repeated_primitives: bool = ...,
pointy_brackets: bool = ...,
use_index_order: bool = ...,
float_format: Optional[str] = ...,
double_format: Optional[str] = ...,
float_format: str | None = ...,
double_format: str | None = ...,
use_field_number: bool = ...,
descriptor_pool: Optional[DescriptorPool] = ...,
message_formatter: Optional[_MessageFormatter] = ...,
descriptor_pool: DescriptorPool | None = ...,
message_formatter: _MessageFormatter | None = ...,
print_unknown_fields: bool = ...,
force_colon: bool = ...,
) -> None: ...
@@ -141,44 +141,44 @@ class _Printer:
def PrintFieldValue(self, field: FieldDescriptor, value: Any) -> None: ...
def Parse(
text: Union[Text, bytes],
text: Text | bytes,
message: _M,
allow_unknown_extension: bool = ...,
allow_field_number: bool = ...,
descriptor_pool: Optional[DescriptorPool] = ...,
descriptor_pool: DescriptorPool | None = ...,
allow_unknown_field: bool = ...,
) -> _M: ...
def Merge(
text: Union[Text, bytes],
text: Text | bytes,
message: _M,
allow_unknown_extension: bool = ...,
allow_field_number: bool = ...,
descriptor_pool: Optional[DescriptorPool] = ...,
descriptor_pool: DescriptorPool | None = ...,
allow_unknown_field: bool = ...,
) -> _M: ...
def MergeLines(
lines: Iterable[Union[Text, bytes]],
lines: Iterable[Text | bytes],
message: _M,
allow_unknown_extension: bool = ...,
allow_field_number: bool = ...,
descriptor_pool: Optional[DescriptorPool] = ...,
descriptor_pool: DescriptorPool | None = ...,
allow_unknown_field: bool = ...,
) -> _M: ...
class _Parser:
allow_unknown_extension: bool = ...
allow_field_number: bool = ...
descriptor_pool: Optional[DescriptorPool] = ...
descriptor_pool: DescriptorPool | None = ...
allow_unknown_field: bool = ...
def __init__(
self,
allow_unknown_extension: bool = ...,
allow_field_number: bool = ...,
descriptor_pool: Optional[DescriptorPool] = ...,
descriptor_pool: DescriptorPool | None = ...,
allow_unknown_field: bool = ...,
) -> None: ...
def ParseLines(self, lines: Iterable[Union[Text, bytes]], message: _M) -> _M: ...
def MergeLines(self, lines: Iterable[Union[Text, bytes]], message: _M) -> _M: ...
def ParseLines(self, lines: Iterable[Text | bytes], message: _M) -> _M: ...
def MergeLines(self, lines: Iterable[Text | bytes], message: _M) -> _M: ...
_ParseError = ParseError