Use str instead of Text (#7812)

This commit is contained in:
Alex Waygood
2022-05-09 20:47:11 +01:00
committed by GitHub
parent 5c13f8bbce
commit ac30b96d14
7 changed files with 22 additions and 23 deletions

View File

@@ -1,7 +1,7 @@
import abc
import sys
from _typeshed import Self as TypeshedSelf # see #6932 for why the alias cannot have a leading underscore
from typing import ( # noqa: Y022,Y027
from typing import ( # noqa: Y022,Y027,Y039
TYPE_CHECKING as TYPE_CHECKING,
Any,
AsyncContextManager as AsyncContextManager,

View File

@@ -1,5 +1,5 @@
from collections.abc import Callable, Iterable, Iterator, MutableMapping, Sequence
from typing import Any, Text, TypeVar, overload
from typing import Any, 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=bool | int | Text)
_ScalarV = TypeVar("_ScalarV", bound=bool | int | float | Text | bytes)
_K = TypeVar("_K", bound=bool | int | str)
_ScalarV = TypeVar("_ScalarV", bound=bool | int | float | str | bytes)
_MessageV = TypeVar("_MessageV", bound=Message)
_M = TypeVar("_M")

View File

@@ -1,4 +1,4 @@
from typing import Generic, Text, TypeVar
from typing import Generic, TypeVar
from google.protobuf.descriptor import EnumDescriptor
@@ -10,7 +10,7 @@ class _EnumTypeWrapper(Generic[_V]):
DESCRIPTOR: EnumDescriptor
def __init__(self, enum_type: EnumDescriptor) -> None: ...
def Name(self, number: _V) -> str: ...
def Value(self, name: Text | bytes) -> _V: ...
def Value(self, name: str | bytes) -> _V: ...
def keys(self) -> list[str]: ...
def values(self) -> list[_V]: ...
def items(self) -> list[tuple[str, _V]]: ...

View File

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

View File

@@ -1,4 +1,4 @@
from typing import Any, Text, TypeVar
from typing import Any, TypeVar
from google.protobuf.descriptor_pool import DescriptorPool
from google.protobuf.message import Message
@@ -26,9 +26,9 @@ def MessageToDict(
use_integers_for_enums: bool = ...,
descriptor_pool: DescriptorPool | None = ...,
float_precision: int | None = ...,
) -> dict[Text, Any]: ...
) -> dict[str, Any]: ...
def Parse(
text: bytes | Text, message: _MessageT, ignore_unknown_fields: bool = ..., descriptor_pool: DescriptorPool | None = ...
text: bytes | str, message: _MessageT, ignore_unknown_fields: bool = ..., descriptor_pool: DescriptorPool | None = ...
) -> _MessageT: ...
def ParseDict(
js_dict: Any, message: _MessageT, ignore_unknown_fields: bool = ..., descriptor_pool: DescriptorPool | None = ...

View File

@@ -1,6 +1,5 @@
from collections.abc import Callable
from concurrent.futures import Future
from typing import Text
from google.protobuf.descriptor import MethodDescriptor, ServiceDescriptor
from google.protobuf.message import Message
@@ -23,9 +22,9 @@ class Service:
class RpcController:
def Reset(self) -> None: ...
def Failed(self) -> bool: ...
def ErrorText(self) -> Text | None: ...
def ErrorText(self) -> str | None: ...
def StartCancel(self) -> None: ...
def SetFailed(self, reason: Text) -> None: ...
def SetFailed(self, reason: str) -> None: ...
def IsCanceled(self) -> bool: ...
def NotifyOnCancel(self, callback: Callable[[], None]) -> None: ...

View File

@@ -1,6 +1,6 @@
from _typeshed import SupportsWrite
from collections.abc import Callable, Iterable
from typing import Any, Text, TypeVar
from typing import Any, TypeVar
from typing_extensions import TypeAlias
from .descriptor import FieldDescriptor
@@ -18,11 +18,11 @@ class ParseError(Error):
class TextWriter:
def __init__(self, as_utf8: bool) -> None: ...
def write(self, val: Text) -> int: ...
def write(self, val: str) -> int: ...
def getvalue(self) -> str: ...
def close(self) -> None: ...
_MessageFormatter: TypeAlias = Callable[[Message, int, bool], Text | None]
_MessageFormatter: TypeAlias = Callable[[Message, int, bool], str | None]
def MessageToString(
message: Message,
@@ -143,7 +143,7 @@ class _Printer:
def PrintFieldValue(self, field: FieldDescriptor, value: Any) -> None: ...
def Parse(
text: Text | bytes,
text: str | bytes,
message: _M,
allow_unknown_extension: bool = ...,
allow_field_number: bool = ...,
@@ -151,7 +151,7 @@ def Parse(
allow_unknown_field: bool = ...,
) -> _M: ...
def Merge(
text: Text | bytes,
text: str | bytes,
message: _M,
allow_unknown_extension: bool = ...,
allow_field_number: bool = ...,
@@ -159,7 +159,7 @@ def Merge(
allow_unknown_field: bool = ...,
) -> _M: ...
def MergeLines(
lines: Iterable[Text | bytes],
lines: Iterable[str | bytes],
message: _M,
allow_unknown_extension: bool = ...,
allow_field_number: bool = ...,
@@ -179,8 +179,8 @@ class _Parser:
descriptor_pool: DescriptorPool | None = ...,
allow_unknown_field: bool = ...,
) -> None: ...
def ParseLines(self, lines: Iterable[Text | bytes], message: _M) -> _M: ...
def MergeLines(self, lines: Iterable[Text | bytes], message: _M) -> _M: ...
def ParseLines(self, lines: Iterable[str | bytes], message: _M) -> _M: ...
def MergeLines(self, lines: Iterable[str | bytes], message: _M) -> _M: ...
_ParseError: TypeAlias = ParseError
@@ -203,7 +203,7 @@ class Tokenizer:
def ConsumeFloat(self) -> float: ...
def ConsumeBool(self) -> bool: ...
def TryConsumeByteString(self) -> bool: ...
def ConsumeString(self) -> Text: ...
def ConsumeString(self) -> str: ...
def ConsumeByteString(self) -> bytes: ...
def ConsumeEnum(self, field: FieldDescriptor) -> int: ...
def ParseErrorPreviousToken(self, message: Message) -> _ParseError: ...