From ebcdcfa24ef097fa3b0ab000198ef6613efea419 Mon Sep 17 00:00:00 2001 From: Aaron Sykes Date: Fri, 4 Feb 2022 12:05:58 -0800 Subject: [PATCH] Makes `DESCRIPTOR` non nullable again (#7125) Co-authored-by: Jelle Zijlstra --- stubs/protobuf/@tests/stubtest_allowlist.txt | 6 ++++++ .../protobuf/google/protobuf/internal/enum_type_wrapper.pyi | 2 +- stubs/protobuf/google/protobuf/message.pyi | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/stubs/protobuf/@tests/stubtest_allowlist.txt b/stubs/protobuf/@tests/stubtest_allowlist.txt index f8083071d..8b8dfb1a9 100644 --- a/stubs/protobuf/@tests/stubtest_allowlist.txt +++ b/stubs/protobuf/@tests/stubtest_allowlist.txt @@ -3,6 +3,12 @@ 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 google.protobuf.message.Message.SerializePartialToString google.protobuf.message.Message.SerializeToString google.protobuf.service.Service.GetDescriptor diff --git a/stubs/protobuf/google/protobuf/internal/enum_type_wrapper.pyi b/stubs/protobuf/google/protobuf/internal/enum_type_wrapper.pyi index 3abc44b26..47f40a972 100644 --- a/stubs/protobuf/google/protobuf/internal/enum_type_wrapper.pyi +++ b/stubs/protobuf/google/protobuf/internal/enum_type_wrapper.pyi @@ -7,7 +7,7 @@ _V = TypeVar("_V", bound=int) # Expose a generic version so that those using mypy-protobuf # can get autogenerated NewType wrapper around the int values class _EnumTypeWrapper(Generic[_V]): - DESCRIPTOR: EnumDescriptor | None + DESCRIPTOR: EnumDescriptor def __init__(self, enum_type: EnumDescriptor) -> None: ... def Name(self, number: _V) -> str: ... def Value(self, name: Text | bytes) -> _V: ... diff --git a/stubs/protobuf/google/protobuf/message.pyi b/stubs/protobuf/google/protobuf/message.pyi index 665941f08..c346b5363 100644 --- a/stubs/protobuf/google/protobuf/message.pyi +++ b/stubs/protobuf/google/protobuf/message.pyi @@ -11,7 +11,7 @@ class EncodeError(Error): ... _M = TypeVar("_M", bound=Message) # message type (of self) class Message: - DESCRIPTOR: Descriptor | None + DESCRIPTOR: Descriptor def __deepcopy__(self, memo=...): ... def __eq__(self, other_msg): ... def __ne__(self, other_msg): ...