Skip to content

Commit c17c0d5

Browse files
authored
Bump protobuf to 3.20.1 (#8609)
There are even newer versions available (4.*), but I had found a bug in it which prevented it from working with mypy-protobuf. For now, sticking to just 3.20.1
1 parent 1c56148 commit c17c0d5

File tree

9 files changed

+50
-22
lines changed

9 files changed

+50
-22
lines changed

scripts/generate_proto_stubs.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ set -ex -o pipefail
1111
# followed by committing the changes to typeshed
1212
#
1313
# Update these two variables when rerunning script
14-
PROTOBUF_VERSION=3.19.3
14+
PROTOBUF_VERSION=3.20.1
1515
MYPY_PROTOBUF_VERSION=v3.2.0
1616

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

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

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

7475
isort "$REPO_ROOT/stubs/protobuf"

stubs/protobuf/@tests/stubtest_allowlist.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@ google.protobuf.descriptor.Descriptor.__init__
3232
google.protobuf.descriptor.Descriptor.__new__
3333
google.protobuf.descriptor.ServiceDescriptor.__init__
3434
google.protobuf.descriptor.ServiceDescriptor.__new__
35+
36+
# Set to None at runtime - which doesn't match the Sequence base class.
37+
# It's a hack - just allow it.
38+
google.protobuf.internal.containers.BaseContainer.__hash__

stubs/protobuf/METADATA.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
version = "3.19.*"
1+
version = "3.20.*"
22
extra_description = "Generated with aid from mypy-protobuf v3.2.0"

stubs/protobuf/google/protobuf/any_pb2.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Any(google.protobuf.message.Message, google.protobuf.internal.well_known_t
3737
foo = any.unpack(Foo.class);
3838
}
3939
40-
Example 3: Pack and unpack a message in Python.
40+
Example 3: Pack and unpack a message in Python.
4141
4242
foo = Foo(...)
4343
any = Any()
@@ -47,7 +47,7 @@ class Any(google.protobuf.message.Message, google.protobuf.internal.well_known_t
4747
any.Unpack(foo)
4848
...
4949
50-
Example 4: Pack and unpack a message in Go
50+
Example 4: Pack and unpack a message in Go
5151
5252
foo := &pb.Foo{...}
5353
any, err := anypb.New(foo)
@@ -68,7 +68,7 @@ class Any(google.protobuf.message.Message, google.protobuf.internal.well_known_t
6868
6969
7070
JSON
71-
====
71+
7272
The JSON representation of an `Any` value uses the regular
7373
representation of the deserialized, embedded message, with an
7474
additional field `@type` which contains the type URL. Example:

stubs/protobuf/google/protobuf/descriptor.pyi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ class MethodDescriptor(DescriptorBase):
240240
containing_service,
241241
input_type,
242242
output_type,
243+
client_streaming=...,
244+
server_streaming=...,
243245
options=...,
244246
serialized_options=...,
245247
create_key=...,
@@ -250,6 +252,8 @@ class MethodDescriptor(DescriptorBase):
250252
containing_service: Any
251253
input_type: Any
252254
output_type: Any
255+
client_streaming: bool
256+
server_streaming: bool
253257
def __init__(
254258
self,
255259
name,
@@ -258,6 +262,8 @@ class MethodDescriptor(DescriptorBase):
258262
containing_service,
259263
input_type,
260264
output_type,
265+
client_streaming=...,
266+
server_streaming=...,
261267
options=...,
262268
serialized_options=...,
263269
create_key=...,

stubs/protobuf/google/protobuf/descriptor_pb2.pyi

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,6 @@ class FieldDescriptorProto(google.protobuf.message.Message):
373373
For booleans, "true" or "false".
374374
For strings, contains the default text contents (not escaped in any way).
375375
For bytes, contains the C escaped value. All bytes >= 128 are escaped.
376-
TODO(kenton): Base-64 encode?
377376
"""
378377

379378
oneof_index: builtins.int
@@ -956,6 +955,7 @@ class FieldOptions(google.protobuf.message.Message):
956955
PACKED_FIELD_NUMBER: builtins.int
957956
JSTYPE_FIELD_NUMBER: builtins.int
958957
LAZY_FIELD_NUMBER: builtins.int
958+
UNVERIFIED_LAZY_FIELD_NUMBER: builtins.int
959959
DEPRECATED_FIELD_NUMBER: builtins.int
960960
WEAK_FIELD_NUMBER: builtins.int
961961
UNINTERPRETED_OPTION_FIELD_NUMBER: builtins.int
@@ -1017,6 +1017,18 @@ class FieldOptions(google.protobuf.message.Message):
10171017
implementation must either *always* check its required fields, or *never*
10181018
check its required fields, regardless of whether or not the message has
10191019
been parsed.
1020+
1021+
As of 2021, lazy does no correctness checks on the byte stream during
1022+
parsing. This may lead to crashes if and when an invalid byte stream is
1023+
finally parsed upon access.
1024+
1025+
TODO(b/211906113): Enable validation on lazy fields.
1026+
"""
1027+
1028+
unverified_lazy: builtins.bool
1029+
"""unverified_lazy does no correctness checks on the byte stream. This should
1030+
only be used where lazy with verification is prohibitive for performance
1031+
reasons.
10201032
"""
10211033

10221034
deprecated: builtins.bool
@@ -1039,12 +1051,13 @@ class FieldOptions(google.protobuf.message.Message):
10391051
packed: typing.Optional[builtins.bool] = ...,
10401052
jstype: typing.Optional[global___FieldOptions.JSType.ValueType] = ...,
10411053
lazy: typing.Optional[builtins.bool] = ...,
1054+
unverified_lazy: typing.Optional[builtins.bool] = ...,
10421055
deprecated: typing.Optional[builtins.bool] = ...,
10431056
weak: typing.Optional[builtins.bool] = ...,
10441057
uninterpreted_option: typing.Optional[typing.Iterable[global___UninterpretedOption]] = ...,
10451058
) -> None: ...
1046-
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: ...
1047-
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: ...
1059+
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: ...
1060+
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: ...
10481061
global___FieldOptions = FieldOptions
10491062

10501063
class OneofOptions(google.protobuf.message.Message):
@@ -1287,8 +1300,8 @@ class SourceCodeInfo(google.protobuf.message.Message):
12871300
location.
12881301
12891302
Each element is a field number or an index. They form a path from
1290-
the root FileDescriptorProto to the place where the definition. For
1291-
example, this path:
1303+
the root FileDescriptorProto to the place where the definition occurs.
1304+
For example, this path:
12921305
[ 4, 3, 2, 7, 1 ]
12931306
refers to:
12941307
file.message_type(3) // 4, 3

stubs/protobuf/google/protobuf/internal/containers.pyi

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ class RepeatedScalarFieldContainer(BaseContainer[_ScalarV]):
3737
def __setitem__(self, key: int, value: _ScalarV) -> None: ...
3838
@overload
3939
def __setitem__(self, key: slice, value: Iterable[_ScalarV]) -> None: ...
40-
def __getslice__(self, start: int, stop: int) -> list[_ScalarV]: ...
41-
def __setslice__(self, start: int, stop: int, values: Iterable[_ScalarV]) -> None: ...
4240
def __delitem__(self, key: int | slice) -> None: ...
43-
def __delslice__(self, start: int, stop: int) -> None: ...
4441
def __eq__(self, other: object) -> bool: ...
4542

4643
class RepeatedCompositeFieldContainer(BaseContainer[_MessageV]):
@@ -52,9 +49,7 @@ class RepeatedCompositeFieldContainer(BaseContainer[_MessageV]):
5249
def MergeFrom(self: _M, other: _M) -> None: ...
5350
def remove(self, elem: _MessageV) -> None: ...
5451
def pop(self, key: int = ...) -> _MessageV: ...
55-
def __getslice__(self, start: int, stop: int) -> list[_MessageV]: ...
5652
def __delitem__(self, key: int | slice) -> None: ...
57-
def __delslice__(self, start: int, stop: int) -> None: ...
5853
def __eq__(self, other: object) -> bool: ...
5954

6055
class ScalarMap(MutableMapping[_K, _ScalarV]):

stubs/protobuf/google/protobuf/internal/well_known_types.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from datetime import datetime, timedelta
1+
from datetime import datetime, timedelta, tzinfo
22
from typing import Any as tAny
33

44
class Any:
@@ -23,7 +23,7 @@ class Timestamp:
2323
def FromMicroseconds(self, micros: int) -> None: ...
2424
def FromMilliseconds(self, millis: int) -> None: ...
2525
def FromSeconds(self, seconds: int) -> None: ...
26-
def ToDatetime(self) -> datetime: ...
26+
def ToDatetime(self, tzinfo: tzinfo | None = ...) -> datetime: ...
2727
def FromDatetime(self, dt: datetime) -> None: ...
2828

2929
class Duration:

stubs/protobuf/google/protobuf/json_format.pyi

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def MessageToJson(
1818
use_integers_for_enums: bool = ...,
1919
descriptor_pool: DescriptorPool | None = ...,
2020
float_precision: int | None = ...,
21+
ensure_ascii: bool = ...,
2122
) -> str: ...
2223
def MessageToDict(
2324
message: Message,
@@ -28,8 +29,16 @@ def MessageToDict(
2829
float_precision: int | None = ...,
2930
) -> dict[str, Any]: ...
3031
def Parse(
31-
text: bytes | str, message: _MessageT, ignore_unknown_fields: bool = ..., descriptor_pool: DescriptorPool | None = ...
32+
text: bytes | str,
33+
message: _MessageT,
34+
ignore_unknown_fields: bool = ...,
35+
descriptor_pool: DescriptorPool | None = ...,
36+
max_recursion_depth: int = ...,
3237
) -> _MessageT: ...
3338
def ParseDict(
34-
js_dict: Any, message: _MessageT, ignore_unknown_fields: bool = ..., descriptor_pool: DescriptorPool | None = ...
39+
js_dict: Any,
40+
message: _MessageT,
41+
ignore_unknown_fields: bool = ...,
42+
descriptor_pool: DescriptorPool | None = ...,
43+
max_recursion_depth: int = ...,
3544
) -> _MessageT: ...

0 commit comments

Comments
 (0)