diff --git a/stubs/protobuf/@tests/stubtest_allowlist.txt b/stubs/protobuf/@tests/stubtest_allowlist.txt index 6913cb412..1d7f7f7a9 100644 --- a/stubs/protobuf/@tests/stubtest_allowlist.txt +++ b/stubs/protobuf/@tests/stubtest_allowlist.txt @@ -16,10 +16,6 @@ google.protobuf.message.Message.Extensions # Has *args that would fail at runtime with any positional argument google.protobuf.internal.containers.BaseContainer.sort -# 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 - # These are deliberately omitted in the stub. # The classes can't be constructed directly anyway, # so the signatures of their constructors are somewhat irrelevant. diff --git a/stubs/protobuf/METADATA.toml b/stubs/protobuf/METADATA.toml index 377d93a1b..a74165071 100644 --- a/stubs/protobuf/METADATA.toml +++ b/stubs/protobuf/METADATA.toml @@ -1,8 +1,8 @@ # Using an exact number in the specifier for scripts/sync_protobuf/google_protobuf.py # When updating, also re-run the script -version = "~=5.29.1" +version = "~=6.30.2" upstream_repository = "https://github.com/protocolbuffers/protobuf" -extra_description = "Partially generated using [mypy-protobuf==3.6.0](https://github.com/nipunn1313/mypy-protobuf/tree/v3.6.0) and libprotoc 28.1 on [protobuf v29.1](https://github.com/protocolbuffers/protobuf/releases/tag/v29.1) (python `protobuf==5.29.1`)." +extra_description = "Partially generated using [mypy-protobuf==3.6.0](https://github.com/nipunn1313/mypy-protobuf/tree/v3.6.0) and libprotoc 29.0 on [protobuf v30.2](https://github.com/protocolbuffers/protobuf/releases/tag/v30.2) (python `protobuf==6.30.2`)." partial_stub = true [tool.stubtest] diff --git a/stubs/protobuf/google/protobuf/__init__.pyi b/stubs/protobuf/google/protobuf/__init__.pyi index bda5b5a7f..c5dd95466 100644 --- a/stubs/protobuf/google/protobuf/__init__.pyi +++ b/stubs/protobuf/google/protobuf/__init__.pyi @@ -1 +1,3 @@ -__version__: str +from typing import Final + +__version__: Final[str] diff --git a/stubs/protobuf/google/protobuf/descriptor_pb2.pyi b/stubs/protobuf/google/protobuf/descriptor_pb2.pyi index ddf523d56..6ff2ce84e 100644 --- a/stubs/protobuf/google/protobuf/descriptor_pb2.pyi +++ b/stubs/protobuf/google/protobuf/descriptor_pb2.pyi @@ -151,9 +151,16 @@ class FileDescriptorProto(google.protobuf.message.Message): The supported values are "proto2", "proto3", and "editions". If `edition` is present, this value must be "editions". + WARNING: This field should only be used by protobuf plugins or special + cases like the proto compiler. Other uses are discouraged and + developers should rely on the protoreflect APIs for their client language. """ edition: global___Edition.ValueType - """The edition of the proto file.""" + """The edition of the proto file. + WARNING: This field should only be used by protobuf plugins or special + cases like the proto compiler. Other uses are discouraged and + developers should rely on the protoreflect APIs for their client language. + """ @property def dependency(self) -> google.protobuf.internal.containers.RepeatedScalarFieldContainer[builtins.str]: """Names of files imported by this file.""" @@ -982,7 +989,11 @@ class FileOptions(google.protobuf.message.Message): """ @property def features(self) -> global___FeatureSet: - """Any features defined in the specific edition.""" + """Any features defined in the specific edition. + WARNING: This field should only be used by protobuf plugins or special + cases like the proto compiler. Other uses are discouraged and + developers should rely on the protoreflect APIs for their client language. + """ @property def uninterpreted_option(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[global___UninterpretedOption]: @@ -1099,7 +1110,11 @@ class MessageOptions(google.protobuf.message.Message): """ @property def features(self) -> global___FeatureSet: - """Any features defined in the specific edition.""" + """Any features defined in the specific edition. + WARNING: This field should only be used by protobuf plugins or special + cases like the proto compiler. Other uses are discouraged and + developers should rely on the protoreflect APIs for their client language. + """ @property def uninterpreted_option(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[global___UninterpretedOption]: @@ -1378,7 +1393,11 @@ class FieldOptions(google.protobuf.message.Message): def edition_defaults(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[global___FieldOptions.EditionDefault]: ... @property def features(self) -> global___FeatureSet: - """Any features defined in the specific edition.""" + """Any features defined in the specific edition. + WARNING: This field should only be used by protobuf plugins or special + cases like the proto compiler. Other uses are discouraged and + developers should rely on the protoreflect APIs for their client language. + """ @property def feature_support(self) -> global___FieldOptions.FeatureSupport: ... @@ -1417,7 +1436,11 @@ class OneofOptions(google.protobuf.message.Message): UNINTERPRETED_OPTION_FIELD_NUMBER: builtins.int @property def features(self) -> global___FeatureSet: - """Any features defined in the specific edition.""" + """Any features defined in the specific edition. + WARNING: This field should only be used by protobuf plugins or special + cases like the proto compiler. Other uses are discouraged and + developers should rely on the protoreflect APIs for their client language. + """ @property def uninterpreted_option(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[global___UninterpretedOption]: @@ -1463,7 +1486,11 @@ class EnumOptions(google.protobuf.message.Message): """ @property def features(self) -> global___FeatureSet: - """Any features defined in the specific edition.""" + """Any features defined in the specific edition. + WARNING: This field should only be used by protobuf plugins or special + cases like the proto compiler. Other uses are discouraged and + developers should rely on the protoreflect APIs for their client language. + """ @property def uninterpreted_option(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[global___UninterpretedOption]: @@ -1505,7 +1532,11 @@ class EnumValueOptions(google.protobuf.message.Message): """ @property def features(self) -> global___FeatureSet: - """Any features defined in the specific edition.""" + """Any features defined in the specific edition. + WARNING: This field should only be used by protobuf plugins or special + cases like the proto compiler. Other uses are discouraged and + developers should rely on the protoreflect APIs for their client language. + """ @property def feature_support(self) -> global___FieldOptions.FeatureSupport: @@ -1549,7 +1580,11 @@ class ServiceOptions(google.protobuf.message.Message): """ @property def features(self) -> global___FeatureSet: - """Any features defined in the specific edition.""" + """Any features defined in the specific edition. + WARNING: This field should only be used by protobuf plugins or special + cases like the proto compiler. Other uses are discouraged and + developers should rely on the protoreflect APIs for their client language. + """ @property def uninterpreted_option(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[global___UninterpretedOption]: @@ -1613,7 +1648,11 @@ class MethodOptions(google.protobuf.message.Message): idempotency_level: global___MethodOptions.IdempotencyLevel.ValueType @property def features(self) -> global___FeatureSet: - """Any features defined in the specific edition.""" + """Any features defined in the specific edition. + WARNING: This field should only be used by protobuf plugins or special + cases like the proto compiler. Other uses are discouraged and + developers should rely on the protoreflect APIs for their client language. + """ @property def uninterpreted_option(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[global___UninterpretedOption]: @@ -1809,18 +1848,35 @@ class FeatureSet(google.protobuf.message.Message): ALLOW: FeatureSet.JsonFormat.ValueType # 1 LEGACY_BEST_EFFORT: FeatureSet.JsonFormat.ValueType # 2 + class _EnforceNamingStyle: + ValueType = typing.NewType("ValueType", builtins.int) + V: typing_extensions.TypeAlias = ValueType + + class _EnforceNamingStyleEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._EnumTypeWrapper[FeatureSet._EnforceNamingStyle.ValueType], builtins.type): + DESCRIPTOR: google.protobuf.descriptor.EnumDescriptor + ENFORCE_NAMING_STYLE_UNKNOWN: FeatureSet._EnforceNamingStyle.ValueType # 0 + STYLE2024: FeatureSet._EnforceNamingStyle.ValueType # 1 + STYLE_LEGACY: FeatureSet._EnforceNamingStyle.ValueType # 2 + + class EnforceNamingStyle(_EnforceNamingStyle, metaclass=_EnforceNamingStyleEnumTypeWrapper): ... + ENFORCE_NAMING_STYLE_UNKNOWN: FeatureSet.EnforceNamingStyle.ValueType # 0 + STYLE2024: FeatureSet.EnforceNamingStyle.ValueType # 1 + STYLE_LEGACY: FeatureSet.EnforceNamingStyle.ValueType # 2 + FIELD_PRESENCE_FIELD_NUMBER: builtins.int ENUM_TYPE_FIELD_NUMBER: builtins.int REPEATED_FIELD_ENCODING_FIELD_NUMBER: builtins.int UTF8_VALIDATION_FIELD_NUMBER: builtins.int MESSAGE_ENCODING_FIELD_NUMBER: builtins.int JSON_FORMAT_FIELD_NUMBER: builtins.int + ENFORCE_NAMING_STYLE_FIELD_NUMBER: builtins.int field_presence: global___FeatureSet.FieldPresence.ValueType enum_type: global___FeatureSet.EnumType.ValueType repeated_field_encoding: global___FeatureSet.RepeatedFieldEncoding.ValueType utf8_validation: global___FeatureSet.Utf8Validation.ValueType message_encoding: global___FeatureSet.MessageEncoding.ValueType json_format: global___FeatureSet.JsonFormat.ValueType + enforce_naming_style: global___FeatureSet.EnforceNamingStyle.ValueType def __init__( self, *, @@ -1830,9 +1886,10 @@ class FeatureSet(google.protobuf.message.Message): utf8_validation: global___FeatureSet.Utf8Validation.ValueType | None = ..., message_encoding: global___FeatureSet.MessageEncoding.ValueType | None = ..., json_format: global___FeatureSet.JsonFormat.ValueType | None = ..., + enforce_naming_style: global___FeatureSet.EnforceNamingStyle.ValueType | None = ..., ) -> None: ... - def HasField(self, field_name: typing.Literal["enum_type", b"enum_type", "field_presence", b"field_presence", "json_format", b"json_format", "message_encoding", b"message_encoding", "repeated_field_encoding", b"repeated_field_encoding", "utf8_validation", b"utf8_validation"]) -> builtins.bool: ... - def ClearField(self, field_name: typing.Literal["enum_type", b"enum_type", "field_presence", b"field_presence", "json_format", b"json_format", "message_encoding", b"message_encoding", "repeated_field_encoding", b"repeated_field_encoding", "utf8_validation", b"utf8_validation"]) -> None: ... + def HasField(self, field_name: typing.Literal["enforce_naming_style", b"enforce_naming_style", "enum_type", b"enum_type", "field_presence", b"field_presence", "json_format", b"json_format", "message_encoding", b"message_encoding", "repeated_field_encoding", b"repeated_field_encoding", "utf8_validation", b"utf8_validation"]) -> builtins.bool: ... + def ClearField(self, field_name: typing.Literal["enforce_naming_style", b"enforce_naming_style", "enum_type", b"enum_type", "field_presence", b"field_presence", "json_format", b"json_format", "message_encoding", b"message_encoding", "repeated_field_encoding", b"repeated_field_encoding", "utf8_validation", b"utf8_validation"]) -> None: ... global___FeatureSet = FeatureSet diff --git a/stubs/protobuf/google/protobuf/internal/containers.pyi b/stubs/protobuf/google/protobuf/internal/containers.pyi index e660140ac..752613716 100644 --- a/stubs/protobuf/google/protobuf/internal/containers.pyi +++ b/stubs/protobuf/google/protobuf/internal/containers.pyi @@ -73,6 +73,7 @@ class ScalarMap(MutableMapping[_K, _ScalarV]): def get(self, key: _K, default: None = None) -> _ScalarV | None: ... @overload def get(self, key: _K, default: _ScalarV | _T) -> _ScalarV | _T: ... + def setdefault(self, key: _K, value: _ScalarV | None = None) -> _ScalarV: ... def MergeFrom(self, other: Self): ... def InvalidateIterators(self) -> None: ... def GetEntryClass(self) -> GeneratedProtocolMessageType: ... @@ -96,6 +97,7 @@ class MessageMap(MutableMapping[_K, _MessageV]): @overload def get(self, key: _K, default: _MessageV | _T) -> _MessageV | _T: ... def get_or_create(self, key: _K) -> _MessageV: ... + def setdefault(self, key: _K, value: _MessageV | None = None) -> _MessageV: ... def MergeFrom(self, other: Self): ... def InvalidateIterators(self) -> None: ... def GetEntryClass(self) -> GeneratedProtocolMessageType: ... diff --git a/stubs/protobuf/google/protobuf/internal/decoder.pyi b/stubs/protobuf/google/protobuf/internal/decoder.pyi index ce74e9318..94ed7f615 100644 --- a/stubs/protobuf/google/protobuf/internal/decoder.pyi +++ b/stubs/protobuf/google/protobuf/internal/decoder.pyi @@ -59,5 +59,3 @@ MESSAGE_SET_ITEM_TAG: bytes def MessageSetItemDecoder(descriptor: Descriptor) -> _Decoder: ... def MapDecoder(field_descriptor, new_default, is_message_map) -> _Decoder: ... - -SkipField: Any diff --git a/stubs/protobuf/google/protobuf/message_factory.pyi b/stubs/protobuf/google/protobuf/message_factory.pyi index 518e12519..6422284aa 100644 --- a/stubs/protobuf/google/protobuf/message_factory.pyi +++ b/stubs/protobuf/google/protobuf/message_factory.pyi @@ -9,8 +9,6 @@ from google.protobuf.message import Message class MessageFactory: pool: Any def __init__(self, pool: DescriptorPool | None = None) -> None: ... - def GetPrototype(self, descriptor: Descriptor) -> type[Message]: ... - def GetMessages(self, files: Iterable[str]) -> dict[str, type[Message]]: ... def GetMessageClass(descriptor: Descriptor) -> type[Message]: ... def GetMessageClassesForFiles(files: Iterable[str], pool: DescriptorPool) -> dict[str, type[Message]]: ... diff --git a/stubs/protobuf/google/protobuf/reflection.pyi b/stubs/protobuf/google/protobuf/reflection.pyi index 5f7822363..2836b3fcf 100644 --- a/stubs/protobuf/google/protobuf/reflection.pyi +++ b/stubs/protobuf/google/protobuf/reflection.pyi @@ -1,5 +1,2 @@ class GeneratedProtocolMessageType(type): def __new__(cls, name, bases, dictionary): ... - -def ParseMessage(descriptor, byte_str): ... -def MakeClass(descriptor): ... diff --git a/stubs/protobuf/google/protobuf/service.pyi b/stubs/protobuf/google/protobuf/service.pyi deleted file mode 100644 index 1123b6134..000000000 --- a/stubs/protobuf/google/protobuf/service.pyi +++ /dev/null @@ -1,39 +0,0 @@ -from collections.abc import Callable -from concurrent.futures import Future - -from google.protobuf.descriptor import MethodDescriptor, ServiceDescriptor -from google.protobuf.message import Message - -class RpcException(Exception): ... - -class Service: - @staticmethod - def GetDescriptor() -> ServiceDescriptor: ... - def CallMethod( - self, - method_descriptor: MethodDescriptor, - rpc_controller: RpcController, - request: 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) -> str | None: ... - def StartCancel(self) -> None: ... - def SetFailed(self, reason: str) -> None: ... - def IsCanceled(self) -> bool: ... - def NotifyOnCancel(self, callback: Callable[[], None]) -> None: ... - -class RpcChannel: - def CallMethod( - self, - method_descriptor: MethodDescriptor, - rpc_controller: RpcController, - request: Message, - response_class: type[Message], - done: Callable[[Message], None] | None, - ) -> Future[Message] | None: ... diff --git a/stubs/protobuf/google/protobuf/wrappers_pb2.pyi b/stubs/protobuf/google/protobuf/wrappers_pb2.pyi index f3c923fea..24aae8997 100644 --- a/stubs/protobuf/google/protobuf/wrappers_pb2.pyi +++ b/stubs/protobuf/google/protobuf/wrappers_pb2.pyi @@ -31,10 +31,17 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -Wrappers for primitive (non-message) types. These types are useful -for embedding primitives in the `google.protobuf.Any` type and for places -where we need to distinguish between the absence of a primitive -typed field and its default value. +Wrappers for primitive (non-message) types. These types were needed +for legacy reasons and are not recommended for use in new APIs. + +Historically these wrappers were useful to have presence on proto3 primitive +fields, but proto3 syntax has been updated to support the `optional` keyword. +Using that keyword is now the strongly preferred way to add presence to +proto3 primitive fields. + +A secondary usecase was to embed primitives in the `google.protobuf.Any` +type: it is now recommended that you embed your value in your own wrapper +message which can be specifically documented. These wrappers have no meaningful use within repeated fields as they lack the ability to detect presence on individual elements. @@ -55,6 +62,9 @@ class DoubleValue(google.protobuf.message.Message): """Wrapper message for `double`. The JSON representation for `DoubleValue` is JSON number. + + Not recommended for use in new APIs, but still useful for legacy APIs and + has no plan to be removed. """ DESCRIPTOR: google.protobuf.descriptor.Descriptor @@ -76,6 +86,9 @@ class FloatValue(google.protobuf.message.Message): """Wrapper message for `float`. The JSON representation for `FloatValue` is JSON number. + + Not recommended for use in new APIs, but still useful for legacy APIs and + has no plan to be removed. """ DESCRIPTOR: google.protobuf.descriptor.Descriptor @@ -97,6 +110,9 @@ class Int64Value(google.protobuf.message.Message): """Wrapper message for `int64`. The JSON representation for `Int64Value` is JSON string. + + Not recommended for use in new APIs, but still useful for legacy APIs and + has no plan to be removed. """ DESCRIPTOR: google.protobuf.descriptor.Descriptor @@ -118,6 +134,9 @@ class UInt64Value(google.protobuf.message.Message): """Wrapper message for `uint64`. The JSON representation for `UInt64Value` is JSON string. + + Not recommended for use in new APIs, but still useful for legacy APIs and + has no plan to be removed. """ DESCRIPTOR: google.protobuf.descriptor.Descriptor @@ -139,6 +158,9 @@ class Int32Value(google.protobuf.message.Message): """Wrapper message for `int32`. The JSON representation for `Int32Value` is JSON number. + + Not recommended for use in new APIs, but still useful for legacy APIs and + has no plan to be removed. """ DESCRIPTOR: google.protobuf.descriptor.Descriptor @@ -160,6 +182,9 @@ class UInt32Value(google.protobuf.message.Message): """Wrapper message for `uint32`. The JSON representation for `UInt32Value` is JSON number. + + Not recommended for use in new APIs, but still useful for legacy APIs and + has no plan to be removed. """ DESCRIPTOR: google.protobuf.descriptor.Descriptor @@ -181,6 +206,9 @@ class BoolValue(google.protobuf.message.Message): """Wrapper message for `bool`. The JSON representation for `BoolValue` is JSON `true` and `false`. + + Not recommended for use in new APIs, but still useful for legacy APIs and + has no plan to be removed. """ DESCRIPTOR: google.protobuf.descriptor.Descriptor @@ -202,6 +230,9 @@ class StringValue(google.protobuf.message.Message): """Wrapper message for `string`. The JSON representation for `StringValue` is JSON string. + + Not recommended for use in new APIs, but still useful for legacy APIs and + has no plan to be removed. """ DESCRIPTOR: google.protobuf.descriptor.Descriptor @@ -223,6 +254,9 @@ class BytesValue(google.protobuf.message.Message): """Wrapper message for `bytes`. The JSON representation for `BytesValue` is JSON string. + + Not recommended for use in new APIs, but still useful for legacy APIs and + has no plan to be removed. """ DESCRIPTOR: google.protobuf.descriptor.Descriptor