Skip to content

Commit 581b2d5

Browse files
authored
Update protobuf generated stubs from mypy-protobuf 2.8 (#5804)
1 parent af9b46a commit 581b2d5

15 files changed

+1534
-258
lines changed

scripts/generate_proto_stubs.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# Update these two variables when rerunning script
1212
PROTOBUF_VERSION=3.17.3
13-
MYPY_PROTOBUF_VERSION=v2.6
13+
MYPY_PROTOBUF_VERSION=v2.8
1414

1515
set -ex
1616

@@ -73,3 +73,5 @@ protoc_install/bin/protoc --proto_path=$PYTHON_PROTOBUF_DIR/src --mypy_out=$REPO
7373

7474
isort $REPO_ROOT/stubs/protobuf
7575
black $REPO_ROOT/stubs/protobuf
76+
77+
sed -i="" "s/mypy-protobuf [^\"]*/mypy-protobuf ${MYPY_PROTOBUF_VERSION}/" $REPO_ROOT/stubs/protobuf/METADATA.toml

stubs/protobuf/@tests/stubtest_allowlist.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ google.protobuf.compiler.plugin_pb2.CodeGeneratorResponse.FEATURE_PROTO3_OPTIONA
99
google.protobuf.compiler.plugin_pb2.CodeGeneratorResponse.Feature
1010
google.protobuf.compiler.plugin_pb2.CodeGeneratorResponse.File.__init__
1111
google.protobuf.compiler.plugin_pb2.CodeGeneratorResponse._Feature
12+
google.protobuf.compiler.plugin_pb2.CodeGeneratorResponse._FeatureEnumTypeWrapper
1213
google.protobuf.compiler.plugin_pb2.CodeGeneratorResponse.__init__
1314
google.protobuf.compiler.plugin_pb2.Version.__init__
1415
google.protobuf.descriptor.Descriptor.__new__
@@ -49,7 +50,9 @@ google.protobuf.descriptor_pb2.FieldDescriptorProto.TYPE_UINT32
4950
google.protobuf.descriptor_pb2.FieldDescriptorProto.TYPE_UINT64
5051
google.protobuf.descriptor_pb2.FieldDescriptorProto.Type
5152
google.protobuf.descriptor_pb2.FieldDescriptorProto._Label
53+
google.protobuf.descriptor_pb2.FieldDescriptorProto._LabelEnumTypeWrapper
5254
google.protobuf.descriptor_pb2.FieldDescriptorProto._Type
55+
google.protobuf.descriptor_pb2.FieldDescriptorProto._TypeEnumTypeWrapper
5356
google.protobuf.descriptor_pb2.FieldDescriptorProto.__init__
5457
google.protobuf.descriptor_pb2.FieldOptions.CORD
5558
google.protobuf.descriptor_pb2.FieldOptions.CType
@@ -60,7 +63,9 @@ google.protobuf.descriptor_pb2.FieldOptions.JS_STRING
6063
google.protobuf.descriptor_pb2.FieldOptions.STRING
6164
google.protobuf.descriptor_pb2.FieldOptions.STRING_PIECE
6265
google.protobuf.descriptor_pb2.FieldOptions._CType
66+
google.protobuf.descriptor_pb2.FieldOptions._CTypeEnumTypeWrapper
6367
google.protobuf.descriptor_pb2.FieldOptions._JSType
68+
google.protobuf.descriptor_pb2.FieldOptions._JSTypeEnumTypeWrapper
6469
google.protobuf.descriptor_pb2.FieldOptions.__init__
6570
google.protobuf.descriptor_pb2.FileDescriptorProto.__init__
6671
google.protobuf.descriptor_pb2.FileDescriptorSet.__init__
@@ -69,6 +74,7 @@ google.protobuf.descriptor_pb2.FileOptions.LITE_RUNTIME
6974
google.protobuf.descriptor_pb2.FileOptions.OptimizeMode
7075
google.protobuf.descriptor_pb2.FileOptions.SPEED
7176
google.protobuf.descriptor_pb2.FileOptions._OptimizeMode
77+
google.protobuf.descriptor_pb2.FileOptions._OptimizeModeEnumTypeWrapper
7278
google.protobuf.descriptor_pb2.FileOptions.__init__
7379
google.protobuf.descriptor_pb2.GeneratedCodeInfo.Annotation.__init__
7480
google.protobuf.descriptor_pb2.GeneratedCodeInfo.__init__
@@ -79,6 +85,7 @@ google.protobuf.descriptor_pb2.MethodOptions.IDEMPOTENT
7985
google.protobuf.descriptor_pb2.MethodOptions.IdempotencyLevel
8086
google.protobuf.descriptor_pb2.MethodOptions.NO_SIDE_EFFECTS
8187
google.protobuf.descriptor_pb2.MethodOptions._IdempotencyLevel
88+
google.protobuf.descriptor_pb2.MethodOptions._IdempotencyLevelEnumTypeWrapper
8289
google.protobuf.descriptor_pb2.MethodOptions.__init__
8390
google.protobuf.descriptor_pb2.OneofDescriptorProto.__init__
8491
google.protobuf.descriptor_pb2.OneofOptions.__init__
@@ -154,7 +161,9 @@ google.protobuf.type_pb2.Field.TYPE_UINT32
154161
google.protobuf.type_pb2.Field.TYPE_UINT64
155162
google.protobuf.type_pb2.Field.TYPE_UNKNOWN
156163
google.protobuf.type_pb2.Field._Cardinality
164+
google.protobuf.type_pb2.Field._CardinalityEnumTypeWrapper
157165
google.protobuf.type_pb2.Field._Kind
166+
google.protobuf.type_pb2.Field._KindEnumTypeWrapper
158167
google.protobuf.type_pb2.Field.__init__
159168
google.protobuf.type_pb2.Option.__init__
160169
google.protobuf.type_pb2.SYNTAX_PROTO2

stubs/protobuf/METADATA.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
version = "3.17"
22
python2 = true
33
requires = ["types-futures"]
4-
extra_description = "Generated with aid from mypy-protobuf 2.6"
4+
extra_description = "Generated with aid from mypy-protobuf v2.8"

stubs/protobuf/google/protobuf/any_pb2.pyi

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,122 @@ import typing_extensions
1111

1212
DESCRIPTOR: google.protobuf.descriptor.FileDescriptor = ...
1313

14+
# `Any` contains an arbitrary serialized protocol buffer message along with a
15+
# URL that describes the type of the serialized message.
16+
#
17+
# Protobuf library provides support to pack/unpack Any values in the form
18+
# of utility functions or additional generated methods of the Any type.
19+
#
20+
# Example 1: Pack and unpack a message in C++.
21+
#
22+
# Foo foo = ...;
23+
# Any any;
24+
# any.PackFrom(foo);
25+
# ...
26+
# if (any.UnpackTo(&foo)) {
27+
# ...
28+
# }
29+
#
30+
# Example 2: Pack and unpack a message in Java.
31+
#
32+
# Foo foo = ...;
33+
# Any any = Any.pack(foo);
34+
# ...
35+
# if (any.is(Foo.class)) {
36+
# foo = any.unpack(Foo.class);
37+
# }
38+
#
39+
# Example 3: Pack and unpack a message in Python.
40+
#
41+
# foo = Foo(...)
42+
# any = Any()
43+
# any.Pack(foo)
44+
# ...
45+
# if any.Is(Foo.DESCRIPTOR):
46+
# any.Unpack(foo)
47+
# ...
48+
#
49+
# Example 4: Pack and unpack a message in Go
50+
#
51+
# foo := &pb.Foo{...}
52+
# any, err := anypb.New(foo)
53+
# if err != nil {
54+
# ...
55+
# }
56+
# ...
57+
# foo := &pb.Foo{}
58+
# if err := any.UnmarshalTo(foo); err != nil {
59+
# ...
60+
# }
61+
#
62+
# The pack methods provided by protobuf library will by default use
63+
# 'type.googleapis.com/full.type.name' as the type URL and the unpack
64+
# methods only use the fully qualified type name after the last '/'
65+
# in the type URL, for example "foo.bar.com/x/y.z" will yield type
66+
# name "y.z".
67+
#
68+
#
69+
# JSON
70+
# ====
71+
# The JSON representation of an `Any` value uses the regular
72+
# representation of the deserialized, embedded message, with an
73+
# additional field `@type` which contains the type URL. Example:
74+
#
75+
# package google.profile;
76+
# message Person {
77+
# string first_name = 1;
78+
# string last_name = 2;
79+
# }
80+
#
81+
# {
82+
# "@type": "type.googleapis.com/google.profile.Person",
83+
# "firstName": <string>,
84+
# "lastName": <string>
85+
# }
86+
#
87+
# If the embedded message type is well-known and has a custom JSON
88+
# representation, that representation will be embedded adding a field
89+
# `value` which holds the custom JSON in addition to the `@type`
90+
# field. Example (for message [google.protobuf.Duration][]):
91+
#
92+
# {
93+
# "@type": "type.googleapis.com/google.protobuf.Duration",
94+
# "value": "1.212s"
95+
# }
1496
class Any(google.protobuf.message.Message, google.protobuf.internal.well_known_types.Any):
1597
DESCRIPTOR: google.protobuf.descriptor.Descriptor = ...
1698
TYPE_URL_FIELD_NUMBER: builtins.int
1799
VALUE_FIELD_NUMBER: builtins.int
100+
# A URL/resource name that uniquely identifies the type of the serialized
101+
# protocol buffer message. This string must contain at least
102+
# one "/" character. The last segment of the URL's path must represent
103+
# the fully qualified name of the type (as in
104+
# `path/google.protobuf.Duration`). The name should be in a canonical form
105+
# (e.g., leading "." is not accepted).
106+
#
107+
# In practice, teams usually precompile into the binary all types that they
108+
# expect it to use in the context of Any. However, for URLs which use the
109+
# scheme `http`, `https`, or no scheme, one can optionally set up a type
110+
# server that maps type URLs to message definitions as follows:
111+
#
112+
# * If no scheme is provided, `https` is assumed.
113+
# * An HTTP GET on the URL must yield a [google.protobuf.Type][]
114+
# value in binary format, or produce an error.
115+
# * Applications are allowed to cache lookup results based on the
116+
# URL, or have them precompiled into a binary to avoid any
117+
# lookup. Therefore, binary compatibility needs to be preserved
118+
# on changes to types. (Use versioned type names to manage
119+
# breaking changes.)
120+
#
121+
# Note: this functionality is not currently available in the official
122+
# protobuf release, and it is not used for type URLs beginning with
123+
# type.googleapis.com.
124+
#
125+
# Schemes other than `http`, `https` (or the empty scheme) might be
126+
# used with implementation specific semantics.
18127
type_url: typing.Text = ...
128+
# Must be a valid serialized protocol buffer of the above specified type.
19129
value: builtins.bytes = ...
20-
21130
def __init__(self,
22131
*,
23132
type_url : typing.Text = ...,

stubs/protobuf/google/protobuf/api_pb2.pyi

Lines changed: 128 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ import typing_extensions
1313

1414
DESCRIPTOR: google.protobuf.descriptor.FileDescriptor = ...
1515

16+
# Api is a light-weight descriptor for an API Interface.
17+
#
18+
# Interfaces are also described as "protocol buffer services" in some contexts,
19+
# such as by the "service" keyword in a .proto file, but they are different
20+
# from API Services, which represent a concrete implementation of an interface
21+
# as opposed to simply a description of methods and bindings. They are also
22+
# sometimes simply referred to as "APIs" in other contexts, such as the name of
23+
# this message itself. See https://cloud.google.com/apis/design/glossary for
24+
# detailed terminology.
1625
class Api(google.protobuf.message.Message):
1726
DESCRIPTOR: google.protobuf.descriptor.Descriptor = ...
1827
NAME_FIELD_NUMBER: builtins.int
@@ -22,22 +31,44 @@ class Api(google.protobuf.message.Message):
2231
SOURCE_CONTEXT_FIELD_NUMBER: builtins.int
2332
MIXINS_FIELD_NUMBER: builtins.int
2433
SYNTAX_FIELD_NUMBER: builtins.int
34+
# The fully qualified name of this interface, including package name
35+
# followed by the interface's simple name.
2536
name: typing.Text = ...
26-
version: typing.Text = ...
27-
syntax: google.protobuf.type_pb2.Syntax.V = ...
28-
37+
# The methods of this interface, in unspecified order.
2938
@property
3039
def methods(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[global___Method]: ...
31-
40+
# Any metadata attached to the interface.
3241
@property
3342
def options(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[google.protobuf.type_pb2.Option]: ...
34-
43+
# A version string for this interface. If specified, must have the form
44+
# `major-version.minor-version`, as in `1.10`. If the minor version is
45+
# omitted, it defaults to zero. If the entire version field is empty, the
46+
# major version is derived from the package name, as outlined below. If the
47+
# field is not empty, the version in the package name will be verified to be
48+
# consistent with what is provided here.
49+
#
50+
# The versioning schema uses [semantic
51+
# versioning](http://semver.org) where the major version number
52+
# indicates a breaking change and the minor version an additive,
53+
# non-breaking change. Both version numbers are signals to users
54+
# what to expect from different versions, and should be carefully
55+
# chosen based on the product plan.
56+
#
57+
# The major version is also reflected in the package name of the
58+
# interface, which must end in `v<major-version>`, as in
59+
# `google.feature.v1`. For major versions 0 and 1, the suffix can
60+
# be omitted. Zero major versions must only be used for
61+
# experimental, non-GA interfaces.
62+
version: typing.Text = ...
63+
# Source context for the protocol buffer service represented by this
64+
# message.
3565
@property
3666
def source_context(self) -> google.protobuf.source_context_pb2.SourceContext: ...
37-
67+
# Included interfaces. See [Mixin][].
3868
@property
3969
def mixins(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[global___Mixin]: ...
40-
70+
# The source syntax of the service.
71+
syntax: google.protobuf.type_pb2.Syntax.V = ...
4172
def __init__(self,
4273
*,
4374
name : typing.Text = ...,
@@ -52,6 +83,7 @@ class Api(google.protobuf.message.Message):
5283
def ClearField(self, field_name: typing_extensions.Literal[u"methods",b"methods",u"mixins",b"mixins",u"name",b"name",u"options",b"options",u"source_context",b"source_context",u"syntax",b"syntax",u"version",b"version"]) -> None: ...
5384
global___Api = Api
5485

86+
# Method represents a method of an API interface.
5587
class Method(google.protobuf.message.Message):
5688
DESCRIPTOR: google.protobuf.descriptor.Descriptor = ...
5789
NAME_FIELD_NUMBER: builtins.int
@@ -61,16 +93,21 @@ class Method(google.protobuf.message.Message):
6193
RESPONSE_STREAMING_FIELD_NUMBER: builtins.int
6294
OPTIONS_FIELD_NUMBER: builtins.int
6395
SYNTAX_FIELD_NUMBER: builtins.int
96+
# The simple name of this method.
6497
name: typing.Text = ...
98+
# A URL of the input message type.
6599
request_type_url: typing.Text = ...
100+
# If true, the request is streamed.
66101
request_streaming: builtins.bool = ...
102+
# The URL of the output message type.
67103
response_type_url: typing.Text = ...
104+
# If true, the response is streamed.
68105
response_streaming: builtins.bool = ...
69-
syntax: google.protobuf.type_pb2.Syntax.V = ...
70-
106+
# Any metadata attached to the method.
71107
@property
72108
def options(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[google.protobuf.type_pb2.Option]: ...
73-
109+
# The source syntax of this method.
110+
syntax: google.protobuf.type_pb2.Syntax.V = ...
74111
def __init__(self,
75112
*,
76113
name : typing.Text = ...,
@@ -84,13 +121,93 @@ class Method(google.protobuf.message.Message):
84121
def ClearField(self, field_name: typing_extensions.Literal[u"name",b"name",u"options",b"options",u"request_streaming",b"request_streaming",u"request_type_url",b"request_type_url",u"response_streaming",b"response_streaming",u"response_type_url",b"response_type_url",u"syntax",b"syntax"]) -> None: ...
85122
global___Method = Method
86123

124+
# Declares an API Interface to be included in this interface. The including
125+
# interface must redeclare all the methods from the included interface, but
126+
# documentation and options are inherited as follows:
127+
#
128+
# - If after comment and whitespace stripping, the documentation
129+
# string of the redeclared method is empty, it will be inherited
130+
# from the original method.
131+
#
132+
# - Each annotation belonging to the service config (http,
133+
# visibility) which is not set in the redeclared method will be
134+
# inherited.
135+
#
136+
# - If an http annotation is inherited, the path pattern will be
137+
# modified as follows. Any version prefix will be replaced by the
138+
# version of the including interface plus the [root][] path if
139+
# specified.
140+
#
141+
# Example of a simple mixin:
142+
#
143+
# package google.acl.v1;
144+
# service AccessControl {
145+
# // Get the underlying ACL object.
146+
# rpc GetAcl(GetAclRequest) returns (Acl) {
147+
# option (google.api.http).get = "/v1/{resource=**}:getAcl";
148+
# }
149+
# }
150+
#
151+
# package google.storage.v2;
152+
# service Storage {
153+
# rpc GetAcl(GetAclRequest) returns (Acl);
154+
#
155+
# // Get a data record.
156+
# rpc GetData(GetDataRequest) returns (Data) {
157+
# option (google.api.http).get = "/v2/{resource=**}";
158+
# }
159+
# }
160+
#
161+
# Example of a mixin configuration:
162+
#
163+
# apis:
164+
# - name: google.storage.v2.Storage
165+
# mixins:
166+
# - name: google.acl.v1.AccessControl
167+
#
168+
# The mixin construct implies that all methods in `AccessControl` are
169+
# also declared with same name and request/response types in
170+
# `Storage`. A documentation generator or annotation processor will
171+
# see the effective `Storage.GetAcl` method after inheriting
172+
# documentation and annotations as follows:
173+
#
174+
# service Storage {
175+
# // Get the underlying ACL object.
176+
# rpc GetAcl(GetAclRequest) returns (Acl) {
177+
# option (google.api.http).get = "/v2/{resource=**}:getAcl";
178+
# }
179+
# ...
180+
# }
181+
#
182+
# Note how the version in the path pattern changed from `v1` to `v2`.
183+
#
184+
# If the `root` field in the mixin is specified, it should be a
185+
# relative path under which inherited HTTP paths are placed. Example:
186+
#
187+
# apis:
188+
# - name: google.storage.v2.Storage
189+
# mixins:
190+
# - name: google.acl.v1.AccessControl
191+
# root: acls
192+
#
193+
# This implies the following inherited HTTP annotation:
194+
#
195+
# service Storage {
196+
# // Get the underlying ACL object.
197+
# rpc GetAcl(GetAclRequest) returns (Acl) {
198+
# option (google.api.http).get = "/v2/acls/{resource=**}:getAcl";
199+
# }
200+
# ...
201+
# }
87202
class Mixin(google.protobuf.message.Message):
88203
DESCRIPTOR: google.protobuf.descriptor.Descriptor = ...
89204
NAME_FIELD_NUMBER: builtins.int
90205
ROOT_FIELD_NUMBER: builtins.int
206+
# The fully qualified name of the interface which is included.
91207
name: typing.Text = ...
208+
# If non-empty specifies a path under which inherited HTTP paths
209+
# are rooted.
92210
root: typing.Text = ...
93-
94211
def __init__(self,
95212
*,
96213
name : typing.Text = ...,

0 commit comments

Comments
 (0)