From 07ea6614c8c03da598903d1fd4fcfd90a35a6ad3 Mon Sep 17 00:00:00 2001 From: Nipunn Koorapati Date: Fri, 22 Feb 2019 22:23:32 -0800 Subject: [PATCH] Genericize types for stringly typed methods on google.protobuf.Message (#2807) --- third_party/2and3/google/protobuf/message.pyi | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/third_party/2and3/google/protobuf/message.pyi b/third_party/2and3/google/protobuf/message.pyi index 3fc8c33d2..0b3e15258 100644 --- a/third_party/2and3/google/protobuf/message.pyi +++ b/third_party/2and3/google/protobuf/message.pyi @@ -1,4 +1,4 @@ -from typing import Any, Sequence, Optional, Text, Tuple +from typing import Any, Sequence, Optional, Tuple from .descriptor import ( DescriptorBase, @@ -28,14 +28,19 @@ class Message: def SerializeToString(self, deterministic: bool = ...) -> bytes: ... def SerializePartialToString(self, deterministic: bool = ...) -> bytes: ... def ListFields(self) -> Sequence[Tuple[FieldDescriptor, Any]]: ... - def HasField(self, field_name: Text) -> bool: ... - def ClearField(self, field_name: Text) -> None: ... - def WhichOneof(self, oneof_group) -> Optional[Text]: ... def HasExtension(self, extension_handle): ... def ClearExtension(self, extension_handle): ... def ByteSize(self) -> int: ... @property def Extensions(self) -> _ExtensionDict: ... + # Intentionally left out typing on these three methods, because they are + # stringly typed and it is not useful to call them on a Message directly. + # We prefer more specific typing on individual subclasses of Message + # See https://github.com/dropbox/mypy-protobuf/issues/62 for details + def HasField(self, field_name: Any) -> bool: ... + def ClearField(self, field_name: Any) -> None: ... + def WhichOneof(self, oneof_group: Any) -> Any: ... + # TODO: check kwargs def __init__(self, **kwargs) -> None: ...