Skip to content

Commit

Permalink
Bump protobuf to v25.3 (#11694)
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam authored Apr 9, 2024
1 parent a1c7926 commit 144ac0a
Show file tree
Hide file tree
Showing 23 changed files with 682 additions and 491 deletions.
21 changes: 9 additions & 12 deletions scripts/generate_proto_stubs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ set -ex -o pipefail
# a meaningful update to either PROTOBUF_VERSION or MYPY_PROTOBUF_VERSION,
# followed by committing the changes to typeshed
#
# Update these two variables when rerunning script
PROTOBUF_VERSION=24.4
MYPY_PROTOBUF_VERSION=3.5.0
# Whenever you update PROTOBUF_VERSION here, version should be updated
# in stubs/protobuf/METADATA.toml and vice-versa.
PROTOBUF_VERSION=25.3
MYPY_PROTOBUF_VERSION=3.6.0

if uname -a | grep Darwin; then
# brew install coreutils wget
Expand Down Expand Up @@ -41,10 +42,9 @@ unzip "$PYTHON_PROTOBUF_FILENAME"
PYTHON_PROTOBUF_DIR="protobuf-$PROTOBUF_VERSION"

# Prepare virtualenv
VENV=venv
python3 -m venv "$VENV"
source "$VENV/bin/activate"
pip install pre-commit mypy-protobuf=="$MYPY_PROTOBUF_VERSION"
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install pre-commit mypy-protobuf=="$MYPY_PROTOBUF_VERSION"

# Remove existing pyi
find "$REPO_ROOT/stubs/protobuf/" -name '*_pb2.pyi' -delete
Expand Down Expand Up @@ -76,10 +76,7 @@ sed --in-place="" \
"$REPO_ROOT/stubs/protobuf/METADATA.toml"

# Must be run in a git repository
cd $REPO_ROOT
cd "$REPO_ROOT"
# use `|| true` so the script still continues even if a pre-commit hook
# applies autofixes (which will result in a nonzero exit code)
pre-commit run --files $(git ls-files -- "$REPO_ROOT/stubs/protobuf") || true
# Ruff takes two passes to fix everything, re-running all of pre-commit is *slow*
# and we don't need --unsafe-fixes to remove imports
ruff check "$REPO_ROOT/stubs/protobuf" --fix --exit-zero
pre-commit run --files $(git ls-files -- "$REPO_ROOT/stubs/protobuf/**_pb2.pyi") || true
6 changes: 4 additions & 2 deletions stubs/protobuf/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
version = "4.24.*"
# Whenever you update version here, PROTOBUF_VERSION should be updated
# in scripts/generate_proto_stubs.sh and vice-versa.
version = "4.25.*"
upstream_repository = "https://github.com/protocolbuffers/protobuf"
extra_description = "Generated using [mypy-protobuf==3.5.0](https://github.com/nipunn1313/mypy-protobuf/tree/v3.5.0) on [protobuf v24.4](https://github.com/protocolbuffers/protobuf/releases/tag/v24.4) (python protobuf==4.24.4)"
extra_description = "Generated using [mypy-protobuf==3.6.0](https://github.com/nipunn1313/mypy-protobuf/tree/v3.6.0) on [protobuf v25.3](https://github.com/protocolbuffers/protobuf/releases/tag/v25.3) (python protobuf==4.25.3)"
partial_stub = true

[tool.stubtest]
Expand Down
7 changes: 4 additions & 3 deletions stubs/protobuf/google/protobuf/any_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +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.
"""

import builtins
import typing as typing_extensions
import typing

import google.protobuf.descriptor
import google.protobuf.internal.well_known_types
import google.protobuf.message

DESCRIPTOR: google.protobuf.descriptor.FileDescriptor

@typing_extensions.final
@typing.final
class Any(google.protobuf.message.Message, google.protobuf.internal.well_known_types.Any):
"""`Any` contains an arbitrary serialized protocol buffer message along with a
URL that describes the type of the serialized message.
Expand Down Expand Up @@ -171,6 +172,6 @@ class Any(google.protobuf.message.Message, google.protobuf.internal.well_known_t
type_url: builtins.str | None = ...,
value: builtins.bytes | None = ...,
) -> None: ...
def ClearField(self, field_name: typing_extensions.Literal["type_url", b"type_url", "value", b"value"]) -> None: ...
def ClearField(self, field_name: typing.Literal["type_url", b"type_url", "value", b"value"]) -> None: ...

global___Any = Any
42 changes: 24 additions & 18 deletions stubs/protobuf/google/protobuf/api_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ 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.
"""

import builtins
import collections.abc
import typing as typing_extensions
import typing

import google.protobuf.descriptor
import google.protobuf.internal.containers
Expand All @@ -43,7 +44,7 @@ import google.protobuf.type_pb2

DESCRIPTOR: google.protobuf.descriptor.FileDescriptor

@typing_extensions.final
@typing.final
class Api(google.protobuf.message.Message):
"""Api is a light-weight descriptor for an API Interface.
Expand All @@ -69,12 +70,6 @@ class Api(google.protobuf.message.Message):
"""The fully qualified name of this interface, including package name
followed by the interface's simple name.
"""
@property
def methods(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[global___Method]:
"""The methods of this interface, in unspecified order."""
@property
def options(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[google.protobuf.type_pb2.Option]:
"""Any metadata attached to the interface."""
version: builtins.str
"""A version string for this interface. If specified, must have the form
`major-version.minor-version`, as in `1.10`. If the minor version is
Expand All @@ -96,16 +91,26 @@ class Api(google.protobuf.message.Message):
be omitted. Zero major versions must only be used for
experimental, non-GA interfaces.
"""
syntax: google.protobuf.type_pb2.Syntax.ValueType
"""The source syntax of the service."""
@property
def methods(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[global___Method]:
"""The methods of this interface, in unspecified order."""

@property
def options(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[google.protobuf.type_pb2.Option]:
"""Any metadata attached to the interface."""

@property
def source_context(self) -> google.protobuf.source_context_pb2.SourceContext:
"""Source context for the protocol buffer service represented by this
message.
"""

@property
def mixins(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[global___Mixin]:
"""Included interfaces. See [Mixin][]."""
syntax: google.protobuf.type_pb2.Syntax.ValueType
"""The source syntax of the service."""

def __init__(
self,
*,
Expand All @@ -117,12 +122,12 @@ class Api(google.protobuf.message.Message):
mixins: collections.abc.Iterable[global___Mixin] | None = ...,
syntax: google.protobuf.type_pb2.Syntax.ValueType | None = ...,
) -> None: ...
def HasField(self, field_name: typing_extensions.Literal["source_context", b"source_context"]) -> builtins.bool: ...
def ClearField(self, field_name: typing_extensions.Literal["methods", b"methods", "mixins", b"mixins", "name", b"name", "options", b"options", "source_context", b"source_context", "syntax", b"syntax", "version", b"version"]) -> None: ...
def HasField(self, field_name: typing.Literal["source_context", b"source_context"]) -> builtins.bool: ...
def ClearField(self, field_name: typing.Literal["methods", b"methods", "mixins", b"mixins", "name", b"name", "options", b"options", "source_context", b"source_context", "syntax", b"syntax", "version", b"version"]) -> None: ...

global___Api = Api

@typing_extensions.final
@typing.final
class Method(google.protobuf.message.Message):
"""Method represents a method of an API interface."""

Expand All @@ -145,11 +150,12 @@ class Method(google.protobuf.message.Message):
"""The URL of the output message type."""
response_streaming: builtins.bool
"""If true, the response is streamed."""
syntax: google.protobuf.type_pb2.Syntax.ValueType
"""The source syntax of this method."""
@property
def options(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[google.protobuf.type_pb2.Option]:
"""Any metadata attached to the method."""
syntax: google.protobuf.type_pb2.Syntax.ValueType
"""The source syntax of this method."""

def __init__(
self,
*,
Expand All @@ -161,11 +167,11 @@ class Method(google.protobuf.message.Message):
options: collections.abc.Iterable[google.protobuf.type_pb2.Option] | None = ...,
syntax: google.protobuf.type_pb2.Syntax.ValueType | None = ...,
) -> None: ...
def ClearField(self, field_name: typing_extensions.Literal["name", b"name", "options", b"options", "request_streaming", b"request_streaming", "request_type_url", b"request_type_url", "response_streaming", b"response_streaming", "response_type_url", b"response_type_url", "syntax", b"syntax"]) -> None: ...
def ClearField(self, field_name: typing.Literal["name", b"name", "options", b"options", "request_streaming", b"request_streaming", "request_type_url", b"request_type_url", "response_streaming", b"response_streaming", "response_type_url", b"response_type_url", "syntax", b"syntax"]) -> None: ...

global___Method = Method

@typing_extensions.final
@typing.final
class Mixin(google.protobuf.message.Message):
"""Declares an API Interface to be included in this interface. The including
interface must redeclare all the methods from the included interface, but
Expand Down Expand Up @@ -263,6 +269,6 @@ class Mixin(google.protobuf.message.Message):
name: builtins.str | None = ...,
root: builtins.str | None = ...,
) -> None: ...
def ClearField(self, field_name: typing_extensions.Literal["name", b"name", "root", b"root"]) -> None: ...
def ClearField(self, field_name: typing.Literal["name", b"name", "root", b"root"]) -> None: ...

global___Mixin = Mixin
34 changes: 20 additions & 14 deletions stubs/protobuf/google/protobuf/compiler/plugin_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ A plugin executable needs only to be placed somewhere in the path. The
plugin should be named "protoc-gen-$NAME", and will then be used when the
flag "--${NAME}_out" is passed to protoc.
"""

import builtins
import collections.abc
import sys
Expand All @@ -32,7 +33,7 @@ else:

DESCRIPTOR: google.protobuf.descriptor.FileDescriptor

@typing_extensions.final
@typing.final
class Version(google.protobuf.message.Message):
"""The version number of protocol compiler."""

Expand All @@ -57,12 +58,12 @@ class Version(google.protobuf.message.Message):
patch: builtins.int | None = ...,
suffix: builtins.str | None = ...,
) -> None: ...
def HasField(self, field_name: typing_extensions.Literal["major", b"major", "minor", b"minor", "patch", b"patch", "suffix", b"suffix"]) -> builtins.bool: ...
def ClearField(self, field_name: typing_extensions.Literal["major", b"major", "minor", b"minor", "patch", b"patch", "suffix", b"suffix"]) -> None: ...
def HasField(self, field_name: typing.Literal["major", b"major", "minor", b"minor", "patch", b"patch", "suffix", b"suffix"]) -> builtins.bool: ...
def ClearField(self, field_name: typing.Literal["major", b"major", "minor", b"minor", "patch", b"patch", "suffix", b"suffix"]) -> None: ...

global___Version = Version

@typing_extensions.final
@typing.final
class CodeGeneratorRequest(google.protobuf.message.Message):
"""An encoded CodeGeneratorRequest is written to the plugin's stdin."""

Expand All @@ -73,14 +74,15 @@ class CodeGeneratorRequest(google.protobuf.message.Message):
PROTO_FILE_FIELD_NUMBER: builtins.int
SOURCE_FILE_DESCRIPTORS_FIELD_NUMBER: builtins.int
COMPILER_VERSION_FIELD_NUMBER: builtins.int
parameter: builtins.str
"""The generator parameter passed on the command-line."""
@property
def file_to_generate(self) -> google.protobuf.internal.containers.RepeatedScalarFieldContainer[builtins.str]:
"""The .proto files that were explicitly listed on the command-line. The
code generator should generate code only for these files. Each file's
descriptor will be included in proto_file, below.
"""
parameter: builtins.str
"""The generator parameter passed on the command-line."""

@property
def proto_file(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[google.protobuf.descriptor_pb2.FileDescriptorProto]:
"""FileDescriptorProtos for all files in files_to_generate and everything
Expand All @@ -103,15 +105,18 @@ class CodeGeneratorRequest(google.protobuf.message.Message):
Type names of fields and extensions in the FileDescriptorProto are always
fully qualified.
"""

@property
def source_file_descriptors(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[google.protobuf.descriptor_pb2.FileDescriptorProto]:
"""File descriptors with all options, including source-retention options.
These descriptors are only provided for the files listed in
files_to_generate.
"""

@property
def compiler_version(self) -> global___Version:
"""The version number of protocol compiler."""

def __init__(
self,
*,
Expand All @@ -121,12 +126,12 @@ class CodeGeneratorRequest(google.protobuf.message.Message):
source_file_descriptors: collections.abc.Iterable[google.protobuf.descriptor_pb2.FileDescriptorProto] | None = ...,
compiler_version: global___Version | None = ...,
) -> None: ...
def HasField(self, field_name: typing_extensions.Literal["compiler_version", b"compiler_version", "parameter", b"parameter"]) -> builtins.bool: ...
def ClearField(self, field_name: typing_extensions.Literal["compiler_version", b"compiler_version", "file_to_generate", b"file_to_generate", "parameter", b"parameter", "proto_file", b"proto_file", "source_file_descriptors", b"source_file_descriptors"]) -> None: ...
def HasField(self, field_name: typing.Literal["compiler_version", b"compiler_version", "parameter", b"parameter"]) -> builtins.bool: ...
def ClearField(self, field_name: typing.Literal["compiler_version", b"compiler_version", "file_to_generate", b"file_to_generate", "parameter", b"parameter", "proto_file", b"proto_file", "source_file_descriptors", b"source_file_descriptors"]) -> None: ...

global___CodeGeneratorRequest = CodeGeneratorRequest

@typing_extensions.final
@typing.final
class CodeGeneratorResponse(google.protobuf.message.Message):
"""The plugin writes an encoded CodeGeneratorResponse to stdout."""

Expand All @@ -149,7 +154,7 @@ class CodeGeneratorResponse(google.protobuf.message.Message):
FEATURE_PROTO3_OPTIONAL: CodeGeneratorResponse.Feature.ValueType # 1
FEATURE_SUPPORTS_EDITIONS: CodeGeneratorResponse.Feature.ValueType # 2

@typing_extensions.final
@typing.final
class File(google.protobuf.message.Message):
"""Represents a single generated file."""

Expand Down Expand Up @@ -219,6 +224,7 @@ class CodeGeneratorResponse(google.protobuf.message.Message):
point is used, this information will be appropriately offset and inserted
into the code generation metadata for the generated files.
"""

def __init__(
self,
*,
Expand All @@ -227,8 +233,8 @@ class CodeGeneratorResponse(google.protobuf.message.Message):
content: builtins.str | None = ...,
generated_code_info: google.protobuf.descriptor_pb2.GeneratedCodeInfo | None = ...,
) -> None: ...
def HasField(self, field_name: typing_extensions.Literal["content", b"content", "generated_code_info", b"generated_code_info", "insertion_point", b"insertion_point", "name", b"name"]) -> builtins.bool: ...
def ClearField(self, field_name: typing_extensions.Literal["content", b"content", "generated_code_info", b"generated_code_info", "insertion_point", b"insertion_point", "name", b"name"]) -> None: ...
def HasField(self, field_name: typing.Literal["content", b"content", "generated_code_info", b"generated_code_info", "insertion_point", b"insertion_point", "name", b"name"]) -> builtins.bool: ...
def ClearField(self, field_name: typing.Literal["content", b"content", "generated_code_info", b"generated_code_info", "insertion_point", b"insertion_point", "name", b"name"]) -> None: ...

ERROR_FIELD_NUMBER: builtins.int
SUPPORTED_FEATURES_FIELD_NUMBER: builtins.int
Expand Down Expand Up @@ -256,7 +262,7 @@ class CodeGeneratorResponse(google.protobuf.message.Message):
supported_features: builtins.int | None = ...,
file: collections.abc.Iterable[global___CodeGeneratorResponse.File] | None = ...,
) -> None: ...
def HasField(self, field_name: typing_extensions.Literal["error", b"error", "supported_features", b"supported_features"]) -> builtins.bool: ...
def ClearField(self, field_name: typing_extensions.Literal["error", b"error", "file", b"file", "supported_features", b"supported_features"]) -> None: ...
def HasField(self, field_name: typing.Literal["error", b"error", "supported_features", b"supported_features"]) -> builtins.bool: ...
def ClearField(self, field_name: typing.Literal["error", b"error", "file", b"file", "supported_features", b"supported_features"]) -> None: ...

global___CodeGeneratorResponse = CodeGeneratorResponse
Loading

0 comments on commit 144ac0a

Please sign in to comment.