Skip to content

Bump protobuf to 3.20.1 #8609

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 4 commits into from
Aug 25, 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
9 changes: 5 additions & 4 deletions scripts/generate_proto_stubs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ set -ex -o pipefail
# followed by committing the changes to typeshed
#
# Update these two variables when rerunning script
PROTOBUF_VERSION=3.19.3
PROTOBUF_VERSION=3.20.1
MYPY_PROTOBUF_VERSION=v3.2.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
MYPY_PROTOBUF_VERSION=v3.2.0
MYPY_PROTOBUF_VERSION=v3.3.0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but I'd like to do it separately - because it ends up having a pretty different set of changes.

I originally was preparing a PR that did both all at once, but it ends up with a bunch of different changes since it changes the code-generator utility.

Would prefer to keep the two PRs isolated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, makes sense!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was also planning to test the changes with 3.3.0 and if things don't work out perfectly, I may have to release 3.3.1 (or 3.4.0) to get typeshed to work.


if uname -a | grep Darwin; then
Expand Down Expand Up @@ -54,11 +54,11 @@ find "$REPO_ROOT/stubs/protobuf/" -name '*_pb2.pyi' -delete

# Roughly reproduce the subset of .proto files on the public interface as described
# by find_package_modules in the protobuf setup.py.
# The logic (as of 3.14.0) can roughly be described as a allowlist of .proto files
# The logic (as of 3.20.1) can roughly be described as a allowlist of .proto files
# further limited to exclude *test* and internal/
# https://github.com/protocolbuffers/protobuf/blob/master/python/setup.py
PROTO_FILES=$(grep "generate_proto.*google" $PYTHON_PROTOBUF_DIR/python/setup.py | \
cut -d\" -f2 | \
PROTO_FILES=$(grep "GenProto.*google" $PYTHON_PROTOBUF_DIR/python/setup.py | \
cut -d\' -f2 | \
grep -v "test" | \
grep -v google/protobuf/internal/ | \
grep -v google/protobuf/pyext/python.proto | \
Expand All @@ -69,6 +69,7 @@ PROTO_FILES=$(grep "generate_proto.*google" $PYTHON_PROTOBUF_DIR/python/setup.py
)

# And regenerate!
# shellcheck disable=SC2086
protoc_install/bin/protoc --proto_path="$PYTHON_PROTOBUF_DIR/src" --mypy_out="relax_strict_optional_primitives:$REPO_ROOT/stubs/protobuf" $PROTO_FILES

isort "$REPO_ROOT/stubs/protobuf"
Expand Down
4 changes: 4 additions & 0 deletions stubs/protobuf/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ google.protobuf.descriptor.Descriptor.__init__
google.protobuf.descriptor.Descriptor.__new__
google.protobuf.descriptor.ServiceDescriptor.__init__
google.protobuf.descriptor.ServiceDescriptor.__new__

# Set to None at runtime - which doesn't match the Sequence base class.
# It's a hack - just allow it.
google.protobuf.internal.containers.BaseContainer.__hash__
2 changes: 1 addition & 1 deletion stubs/protobuf/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = "3.19.*"
version = "3.20.*"
extra_description = "Generated with aid from mypy-protobuf v3.2.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
extra_description = "Generated with aid from mypy-protobuf v3.2.0"
extra_description = "Generated with aid from mypy-protobuf v3.3.0"

6 changes: 3 additions & 3 deletions stubs/protobuf/google/protobuf/any_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Any(google.protobuf.message.Message, google.protobuf.internal.well_known_t
foo = any.unpack(Foo.class);
}

Example 3: Pack and unpack a message in Python.
Example 3: Pack and unpack a message in Python.

foo = Foo(...)
any = Any()
Expand All @@ -47,7 +47,7 @@ class Any(google.protobuf.message.Message, google.protobuf.internal.well_known_t
any.Unpack(foo)
...

Example 4: Pack and unpack a message in Go
Example 4: Pack and unpack a message in Go

foo := &pb.Foo{...}
any, err := anypb.New(foo)
Expand All @@ -68,7 +68,7 @@ class Any(google.protobuf.message.Message, google.protobuf.internal.well_known_t


JSON
====

The JSON representation of an `Any` value uses the regular
representation of the deserialized, embedded message, with an
additional field `@type` which contains the type URL. Example:
Expand Down
6 changes: 6 additions & 0 deletions stubs/protobuf/google/protobuf/descriptor.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ class MethodDescriptor(DescriptorBase):
containing_service,
input_type,
output_type,
client_streaming=...,
server_streaming=...,
options=...,
serialized_options=...,
create_key=...,
Expand All @@ -250,6 +252,8 @@ class MethodDescriptor(DescriptorBase):
containing_service: Any
input_type: Any
output_type: Any
client_streaming: bool
server_streaming: bool
def __init__(
self,
name,
Expand All @@ -258,6 +262,8 @@ class MethodDescriptor(DescriptorBase):
containing_service,
input_type,
output_type,
client_streaming=...,
server_streaming=...,
options=...,
serialized_options=...,
create_key=...,
Expand Down
23 changes: 18 additions & 5 deletions stubs/protobuf/google/protobuf/descriptor_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,6 @@ class FieldDescriptorProto(google.protobuf.message.Message):
For booleans, "true" or "false".
For strings, contains the default text contents (not escaped in any way).
For bytes, contains the C escaped value. All bytes >= 128 are escaped.
TODO(kenton): Base-64 encode?
"""

oneof_index: builtins.int
Expand Down Expand Up @@ -956,6 +955,7 @@ class FieldOptions(google.protobuf.message.Message):
PACKED_FIELD_NUMBER: builtins.int
JSTYPE_FIELD_NUMBER: builtins.int
LAZY_FIELD_NUMBER: builtins.int
UNVERIFIED_LAZY_FIELD_NUMBER: builtins.int
DEPRECATED_FIELD_NUMBER: builtins.int
WEAK_FIELD_NUMBER: builtins.int
UNINTERPRETED_OPTION_FIELD_NUMBER: builtins.int
Expand Down Expand Up @@ -1017,6 +1017,18 @@ class FieldOptions(google.protobuf.message.Message):
implementation must either *always* check its required fields, or *never*
check its required fields, regardless of whether or not the message has
been parsed.

As of 2021, lazy does no correctness checks on the byte stream during
parsing. This may lead to crashes if and when an invalid byte stream is
finally parsed upon access.

TODO(b/211906113): Enable validation on lazy fields.
"""

unverified_lazy: builtins.bool
"""unverified_lazy does no correctness checks on the byte stream. This should
only be used where lazy with verification is prohibitive for performance
reasons.
"""

deprecated: builtins.bool
Expand All @@ -1039,12 +1051,13 @@ class FieldOptions(google.protobuf.message.Message):
packed: typing.Optional[builtins.bool] = ...,
jstype: typing.Optional[global___FieldOptions.JSType.ValueType] = ...,
lazy: typing.Optional[builtins.bool] = ...,
unverified_lazy: typing.Optional[builtins.bool] = ...,
deprecated: typing.Optional[builtins.bool] = ...,
weak: typing.Optional[builtins.bool] = ...,
uninterpreted_option: typing.Optional[typing.Iterable[global___UninterpretedOption]] = ...,
) -> None: ...
def HasField(self, field_name: typing_extensions.Literal["ctype",b"ctype","deprecated",b"deprecated","jstype",b"jstype","lazy",b"lazy","packed",b"packed","weak",b"weak"]) -> builtins.bool: ...
def ClearField(self, field_name: typing_extensions.Literal["ctype",b"ctype","deprecated",b"deprecated","jstype",b"jstype","lazy",b"lazy","packed",b"packed","uninterpreted_option",b"uninterpreted_option","weak",b"weak"]) -> None: ...
def HasField(self, field_name: typing_extensions.Literal["ctype",b"ctype","deprecated",b"deprecated","jstype",b"jstype","lazy",b"lazy","packed",b"packed","unverified_lazy",b"unverified_lazy","weak",b"weak"]) -> builtins.bool: ...
def ClearField(self, field_name: typing_extensions.Literal["ctype",b"ctype","deprecated",b"deprecated","jstype",b"jstype","lazy",b"lazy","packed",b"packed","uninterpreted_option",b"uninterpreted_option","unverified_lazy",b"unverified_lazy","weak",b"weak"]) -> None: ...
global___FieldOptions = FieldOptions

class OneofOptions(google.protobuf.message.Message):
Expand Down Expand Up @@ -1287,8 +1300,8 @@ class SourceCodeInfo(google.protobuf.message.Message):
location.

Each element is a field number or an index. They form a path from
the root FileDescriptorProto to the place where the definition. For
example, this path:
the root FileDescriptorProto to the place where the definition occurs.
For example, this path:
[ 4, 3, 2, 7, 1 ]
refers to:
file.message_type(3) // 4, 3
Expand Down
5 changes: 0 additions & 5 deletions stubs/protobuf/google/protobuf/internal/containers.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ class RepeatedScalarFieldContainer(BaseContainer[_ScalarV]):
def __setitem__(self, key: int, value: _ScalarV) -> None: ...
@overload
def __setitem__(self, key: slice, value: Iterable[_ScalarV]) -> None: ...
def __getslice__(self, start: int, stop: int) -> list[_ScalarV]: ...
def __setslice__(self, start: int, stop: int, values: Iterable[_ScalarV]) -> None: ...
def __delitem__(self, key: int | slice) -> None: ...
def __delslice__(self, start: int, stop: int) -> None: ...
def __eq__(self, other: object) -> bool: ...

class RepeatedCompositeFieldContainer(BaseContainer[_MessageV]):
Expand All @@ -52,9 +49,7 @@ class RepeatedCompositeFieldContainer(BaseContainer[_MessageV]):
def MergeFrom(self: _M, other: _M) -> None: ...
def remove(self, elem: _MessageV) -> None: ...
def pop(self, key: int = ...) -> _MessageV: ...
def __getslice__(self, start: int, stop: int) -> list[_MessageV]: ...
def __delitem__(self, key: int | slice) -> None: ...
def __delslice__(self, start: int, stop: int) -> None: ...
def __eq__(self, other: object) -> bool: ...

class ScalarMap(MutableMapping[_K, _ScalarV]):
Expand Down
4 changes: 2 additions & 2 deletions stubs/protobuf/google/protobuf/internal/well_known_types.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime, timedelta
from datetime import datetime, timedelta, tzinfo
from typing import Any as tAny

class Any:
Expand All @@ -23,7 +23,7 @@ class Timestamp:
def FromMicroseconds(self, micros: int) -> None: ...
def FromMilliseconds(self, millis: int) -> None: ...
def FromSeconds(self, seconds: int) -> None: ...
def ToDatetime(self) -> datetime: ...
def ToDatetime(self, tzinfo: tzinfo | None = ...) -> datetime: ...
def FromDatetime(self, dt: datetime) -> None: ...

class Duration:
Expand Down
13 changes: 11 additions & 2 deletions stubs/protobuf/google/protobuf/json_format.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def MessageToJson(
use_integers_for_enums: bool = ...,
descriptor_pool: DescriptorPool | None = ...,
float_precision: int | None = ...,
ensure_ascii: bool = ...,
) -> str: ...
def MessageToDict(
message: Message,
Expand All @@ -28,8 +29,16 @@ def MessageToDict(
float_precision: int | None = ...,
) -> dict[str, Any]: ...
def Parse(
text: bytes | str, message: _MessageT, ignore_unknown_fields: bool = ..., descriptor_pool: DescriptorPool | None = ...
text: bytes | str,
message: _MessageT,
ignore_unknown_fields: bool = ...,
descriptor_pool: DescriptorPool | None = ...,
max_recursion_depth: int = ...,
) -> _MessageT: ...
def ParseDict(
js_dict: Any, message: _MessageT, ignore_unknown_fields: bool = ..., descriptor_pool: DescriptorPool | None = ...
js_dict: Any,
message: _MessageT,
ignore_unknown_fields: bool = ...,
descriptor_pool: DescriptorPool | None = ...,
max_recursion_depth: int = ...,
) -> _MessageT: ...