Skip to content

Bring back Message.Extensions #7154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions stubs/protobuf/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,24 @@
# carefully in mypy-protobuf which internally runs stubtest. Skip those here.
google.protobuf\..*_pb2\..*

google.protobuf.internal.containers.BaseContainer.sort
# While Message and Descriptor are both defined with a null DESCRIPTOR,
# subclasses of Message and instances of EnumTypeWrapper require this value to
# be set, and since these type stubs are intended for use with protoc-generated
# python it's more accurate to make them non-nullable.
google.protobuf.internal.enum_type_wrapper.EnumTypeWrapper.DESCRIPTOR
google.protobuf.message.Message.DESCRIPTOR

# Exists at runtime, but via a __getitem__/__setitem__ hack
# See https://github.com/protocolbuffers/protobuf/blob/3ea30d80847cd9561db570ae7f673afc15523545/python/google/protobuf/message.py#L67
google.protobuf.message.Message.Extensions

# These are typed as (self, **kwargs) at runtime as thin wrapper functions
# around the underlying true typing. We prefer the true typing
google.protobuf.internal.containers.BaseContainer.sort
google.protobuf.message.Message.SerializePartialToString
google.protobuf.message.Message.SerializeToString
google.protobuf.service.Service.GetDescriptor
google.protobuf.text_format.MessageToBytes

# Stubbed as static method, but actually exists as a property that's
# a function. Typeshed's typing is more useful
google.protobuf.service.Service.GetDescriptor
5 changes: 4 additions & 1 deletion stubs/protobuf/google/protobuf/message.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ from _typeshed import Self
from typing import Any, Sequence, TypeVar

from .descriptor import Descriptor, FieldDescriptor
from .internal.extension_dict import _ExtensionFieldDescriptor
from .internal.extension_dict import _ExtensionDict, _ExtensionFieldDescriptor

class Error(Exception): ...
class DecodeError(Error): ...
Expand All @@ -28,6 +28,9 @@ class Message:
# The TypeVar must be bound to `Message` or we get mypy errors, so we cannot use `Self` for `HasExtension` & `ClearExtension`
def HasExtension(self: _M, extension_handle: _ExtensionFieldDescriptor[_M, Any]) -> bool: ...
def ClearExtension(self: _M, extension_handle: _ExtensionFieldDescriptor[_M, Any]) -> None: ...
# The TypeVar must be bound to `Message` or we get mypy errors, so we cannot use `Self` for `Extensions`
@property
def Extensions(self: _M) -> _ExtensionDict[_M]: ...
def ByteSize(self) -> int: ...
@classmethod
def FromString(cls: type[Self], s: bytes) -> Self: ...
Expand Down