Skip to content
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
4 changes: 2 additions & 2 deletions stubs/protobuf/METADATA.toml
Original file line number Diff line number Diff line change
@@ -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 = "~=7.34.1"
version = "~=7.35.1"
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 34.1 on [protobuf v34.1](https://github.com/protocolbuffers/protobuf/releases/tag/v34.1) (python `protobuf==7.34.1`)."
extra-description = "Partially generated using [mypy-protobuf==3.6.0](https://github.com/nipunn1313/mypy-protobuf/tree/v3.6.0) and libprotoc 35.1 on [protobuf v35.1](https://github.com/protocolbuffers/protobuf/releases/tag/v35.1) (python `protobuf==7.35.1`)."
partial-stub = true

[tool.stubtest]
Expand Down
168 changes: 57 additions & 111 deletions stubs/protobuf/google/protobuf/any_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -46,126 +46,72 @@ class Any(google.protobuf.message.Message, google.protobuf.internal.well_known_t
"""`Any` contains an arbitrary serialized protocol buffer message along with a
URL that describes the type of the serialized message.

Protobuf library provides support to pack/unpack Any values in the form
of utility functions or additional generated methods of the Any type.

Example 1: Pack and unpack a message in C++.

Foo foo = ...;
Any any;
any.PackFrom(foo);
...
if (any.UnpackTo(&foo)) {
...
}

Example 2: Pack and unpack a message in Java.

Foo foo = ...;
Any any = Any.pack(foo);
...
if (any.is(Foo.class)) {
foo = any.unpack(Foo.class);
}
// or ...
if (any.isSameTypeAs(Foo.getDefaultInstance())) {
foo = any.unpack(Foo.getDefaultInstance());
}

Example 3: Pack and unpack a message in Python.

foo = Foo(...)
any = Any()
any.Pack(foo)
...
if any.Is(Foo.DESCRIPTOR):
any.Unpack(foo)
...

Example 4: Pack and unpack a message in Go

foo := &pb.Foo{...}
any, err := anypb.New(foo)
if err != nil {
...
}
...
foo := &pb.Foo{}
if err := any.UnmarshalTo(foo); err != nil {
...
}

The pack methods provided by protobuf library will by default use
'type.googleapis.com/full.type.name' as the type URL and the unpack
methods only use the fully qualified type name after the last '/'
in the type URL, for example "foo.bar.com/x/y.z" will yield type
name "y.z".

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:

package google.profile;
message Person {
string first_name = 1;
string last_name = 2;
}

{
"@type": "type.googleapis.com/google.profile.Person",
"firstName": <string>,
"lastName": <string>
}

If the embedded message type is well-known and has a custom JSON
representation, that representation will be embedded adding a field
`value` which holds the custom JSON in addition to the `@type`
field. Example (for message [google.protobuf.Duration][]):

{
"@type": "type.googleapis.com/google.protobuf.Duration",
"value": "1.212s"
}
In its binary encoding, an `Any` is an ordinary message; but in other wire
forms like JSON, it has a special encoding. The format of the type URL is
described on the `type_url` field.

Protobuf APIs provide utilities to interact with `Any` values:

- A 'pack' operation accepts a message and constructs a generic `Any` wrapper
around it.
- An 'unpack' operation reads the content of an `Any` message, either into an
existing message or a new one. Unpack operations must check the type of the
value they unpack against the declared `type_url`.
- An 'is' operation decides whether an `Any` contains a message of the given
type, i.e. whether it can 'unpack' that type.

The JSON format representation of an `Any` follows one of these cases:

- For types without special-cased JSON encodings, the JSON format
representation of the `Any` is the same as that of the message, with an
additional `@type` field which contains the type URL.
- For types with special-cased JSON encodings (typically called 'well-known'
types, listed in https://protobuf.dev/programming-guides/json/#any), the
JSON format representation has a key `@type` which contains the type URL
and a key `value` which contains the JSON-serialized value.

The text format representation of an `Any` is like a message with one field
whose name is the type URL in brackets. For example, an `Any` containing a
`foo.Bar` message may be written `[type.googleapis.com/foo.Bar] { a: 2 }`.
"""

DESCRIPTOR: google.protobuf.descriptor.Descriptor

TYPE_URL_FIELD_NUMBER: builtins.int
VALUE_FIELD_NUMBER: builtins.int
type_url: builtins.str
"""A URL/resource name that uniquely identifies the type of the serialized
protocol buffer message. This string must contain at least
one "/" character. The last segment of the URL's path must represent
the fully qualified name of the type (as in
`path/google.protobuf.Duration`). The name should be in a canonical form
(e.g., leading "." is not accepted).

In practice, teams usually precompile into the binary all types that they
expect it to use in the context of Any. However, for URLs which use the
scheme `http`, `https`, or no scheme, one can optionally set up a type
server that maps type URLs to message definitions as follows:

* If no scheme is provided, `https` is assumed.
* An HTTP GET on the URL must yield a [google.protobuf.Type][]
value in binary format, or produce an error.
* Applications are allowed to cache lookup results based on the
URL, or have them precompiled into a binary to avoid any
lookup. Therefore, binary compatibility needs to be preserved
on changes to types. (Use versioned type names to manage
breaking changes.)

Note: this functionality is not currently available in the official
protobuf release, and it is not used for type URLs beginning with
type.googleapis.com. As of May 2023, there are no widely used type server
implementations and no plans to implement one.

Schemes other than `http`, `https` (or the empty scheme) might be
used with implementation specific semantics.
"""Identifies the type of the serialized Protobuf message with a URI reference
consisting of a prefix ending in a slash and the fully-qualified type name.

Example: type.googleapis.com/google.protobuf.StringValue

This string must contain at least one `/` character, and the content after
the last `/` must be the fully-qualified name of the type in canonical
form, without a leading dot. Do not write a scheme on these URI references
so that clients do not attempt to contact them.

The prefix is arbitrary and Protobuf implementations are expected to
simply strip off everything up to and including the last `/` to identify
the type. `type.googleapis.com/` is a common default prefix that some
legacy implementations require. This prefix does not indicate the origin of
the type, and URIs containing it are not expected to respond to any
requests.

All type URL strings must be legal URI references with the additional
restriction (for the text format) that the content of the reference
must consist only of alphanumeric characters, percent-encoded escapes, and
characters in the following set (not including the outer backticks):
`/-.~_!$&()*+,;=`. Despite our allowing percent encodings, implementations
should not unescape them to prevent confusion with existing parsers. For
example, `type.googleapis.com%2FFoo` should be rejected.

In the original design of `Any`, the possibility of launching a type
resolution service at these type URLs was considered but Protobuf never
implemented one and considers contacting these URLs to be problematic and
a potential security issue. Do not attempt to contact type URLs.
"""
value: builtins.bytes
"""Must be a valid serialized protocol buffer of the above specified type."""
"""Holds a Protobuf serialization of the type described by type_url."""
def __init__(self, *, type_url: builtins.str | None = ..., value: builtins.bytes | None = ...) -> None: ...
def ClearField(self, field_name: typing.Literal["type_url", b"type_url", "value", b"value"]) -> None: ...

Expand Down
18 changes: 18 additions & 0 deletions stubs/protobuf/google/protobuf/descriptor_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class _EditionEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._EnumTy
comparison.
"""
EDITION_2024: _Edition.ValueType # 1001
EDITION_2026: _Edition.ValueType # 1002
EDITION_UNSTABLE: _Edition.ValueType # 9999
"""A placeholder edition for developing and testing unscheduled features."""
EDITION_1_TEST_ONLY: _Edition.ValueType # 1
"""Placeholder editions for testing feature resolution. These should not be
used or relied on outside of tests.
Expand Down Expand Up @@ -88,6 +91,9 @@ should not be depended on, but they will always be time-ordered for easy
comparison.
"""
EDITION_2024: Edition.ValueType # 1001
EDITION_2026: Edition.ValueType # 1002
EDITION_UNSTABLE: Edition.ValueType # 9999
"""A placeholder edition for developing and testing unscheduled features."""
EDITION_1_TEST_ONLY: Edition.ValueType # 1
"""Placeholder editions for testing feature resolution. These should not be
used or relied on outside of tests.
Expand Down Expand Up @@ -1649,6 +1655,7 @@ class FieldOptions(google.protobuf.message.Message):
EDITION_DEPRECATED_FIELD_NUMBER: builtins.int
DEPRECATION_WARNING_FIELD_NUMBER: builtins.int
EDITION_REMOVED_FIELD_NUMBER: builtins.int
REMOVAL_ERROR_FIELD_NUMBER: builtins.int
edition_introduced: global___Edition.ValueType
"""The edition that this feature was first available in. In editions
earlier than this one, the default assigned to EDITION_LEGACY will be
Expand All @@ -1667,13 +1674,18 @@ class FieldOptions(google.protobuf.message.Message):
this one, the last default assigned will be used, and proto files will
not be able to override it.
"""
removal_error: builtins.str
"""The removal error text if this feature is used after the edition it was
removed in.
"""
def __init__(
self,
*,
edition_introduced: global___Edition.ValueType | None = ...,
edition_deprecated: global___Edition.ValueType | None = ...,
deprecation_warning: builtins.str | None = ...,
edition_removed: global___Edition.ValueType | None = ...,
removal_error: builtins.str | None = ...,
) -> None: ...
def HasField(
self,
Expand All @@ -1686,6 +1698,8 @@ class FieldOptions(google.protobuf.message.Message):
b"edition_introduced",
"edition_removed",
b"edition_removed",
"removal_error",
b"removal_error",
],
) -> builtins.bool: ...
def ClearField(
Expand All @@ -1699,6 +1713,8 @@ class FieldOptions(google.protobuf.message.Message):
b"edition_introduced",
"edition_removed",
b"edition_removed",
"removal_error",
b"removal_error",
],
) -> None: ...

Expand Down Expand Up @@ -2460,11 +2476,13 @@ class FeatureSet(google.protobuf.message.Message):
ENFORCE_NAMING_STYLE_UNKNOWN: FeatureSet._EnforceNamingStyle.ValueType # 0
STYLE2024: FeatureSet._EnforceNamingStyle.ValueType # 1
STYLE_LEGACY: FeatureSet._EnforceNamingStyle.ValueType # 2
STYLE2026: FeatureSet._EnforceNamingStyle.ValueType # 3

class EnforceNamingStyle(_EnforceNamingStyle, metaclass=_EnforceNamingStyleEnumTypeWrapper): ...
ENFORCE_NAMING_STYLE_UNKNOWN: FeatureSet.EnforceNamingStyle.ValueType # 0
STYLE2024: FeatureSet.EnforceNamingStyle.ValueType # 1
STYLE_LEGACY: FeatureSet.EnforceNamingStyle.ValueType # 2
STYLE2026: FeatureSet.EnforceNamingStyle.ValueType # 3

@typing.final
class VisibilityFeature(google.protobuf.message.Message):
Expand Down
34 changes: 16 additions & 18 deletions stubs/protobuf/google/protobuf/field_mask_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -157,24 +157,22 @@ class FieldMask(google.protobuf.message.Message, google.protobuf.internal.well_k
An implementation may provide options to override this default behavior for
repeated and message fields.

In order to reset a field's value to the default, the field must
be in the mask and set to the default value in the provided resource.
Hence, in order to reset all fields of a resource, provide a default
instance of the resource and set all fields in the mask, or do
not provide a mask as described below.

If a field mask is not present on update, the operation applies to
all fields (as if a field mask of all fields has been specified).
Note that in the presence of schema evolution, this may mean that
fields the client does not know and has therefore not filled into
the request will be reset to their default. If this is unwanted
behavior, a specific service may require a client to always specify
a field mask, producing an error if not.

As with get operations, the location of the resource which
describes the updated values in the request message depends on the
operation kind. In any case, the effect of the field mask is
required to be honored by the API.
Note that libraries which implement FieldMask resolution have various
different behaviors in the face of empty masks or the special "*" mask.
When implementing a service you should confirm these cases have the
appropriate behavior in the underlying FieldMask library that you desire,
and you may need to special case those cases in your application code if
the underlying field mask library behavior differs from your intended
service semantics.

Update methods implementing https://google.aip.dev/134
- MUST support the special value * meaning "full replace"
- MUST treat an omitted field mask as "replace fields which are present".

Other methods implementing https://google.aip.dev/157
- SHOULD support the special value "*" to mean "get all".
- MUST treat an omitted field mask to mean "get all", unless otherwise
documented.

## Considerations for HTTP REST

Expand Down
4 changes: 4 additions & 0 deletions stubs/protobuf/google/protobuf/json_format.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ def MessageToJson(
descriptor_pool: DescriptorPool | None = None,
ensure_ascii: bool = True,
always_print_fields_with_no_presence: bool = False,
*,
unquote_int64_if_possible: bool = False,
) -> str: ...
def MessageToDict(
message: Message,
always_print_fields_with_no_presence: bool = False,
preserving_proto_field_name: bool = False,
use_integers_for_enums: bool = False,
descriptor_pool: DescriptorPool | None = None,
*,
unquote_int64_if_possible: bool = False,
) -> dict[str, Any]: ...
def Parse(
text: bytes | str,
Expand Down
Loading