protobuf 6.30.1__py3-none-any.whl → 6.31.0rc1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of protobuf might be problematic. Click here for more details.

@@ -7,4 +7,4 @@
7
7
 
8
8
  # Copyright 2007 Google Inc. All Rights Reserved.
9
9
 
10
- __version__ = '6.30.1'
10
+ __version__ = '6.31.0rc1'
google/protobuf/any.py CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  """Contains the Any helper APIs."""
9
9
 
10
- from typing import Optional
10
+ from typing import Optional, TypeVar
11
11
 
12
12
  from google.protobuf import descriptor
13
13
  from google.protobuf.message import Message
@@ -15,6 +15,9 @@ from google.protobuf.message import Message
15
15
  from google.protobuf.any_pb2 import Any
16
16
 
17
17
 
18
+ _MessageT = TypeVar('_MessageT', bound=Message)
19
+
20
+
18
21
  def pack(
19
22
  msg: Message,
20
23
  type_url_prefix: Optional[str] = 'type.googleapis.com/',
@@ -31,6 +34,17 @@ def unpack(any_msg: Any, msg: Message) -> bool:
31
34
  return any_msg.Unpack(msg=msg)
32
35
 
33
36
 
37
+ def unpack_as(any_msg: Any, message_type: type[_MessageT]) -> _MessageT:
38
+ unpacked = message_type()
39
+ if unpack(any_msg, unpacked):
40
+ return unpacked
41
+ else:
42
+ raise TypeError(
43
+ f'Attempted to unpack {type_name(any_msg)} to'
44
+ f' {message_type.__qualname__}'
45
+ )
46
+
47
+
34
48
  def type_name(any_msg: Any) -> str:
35
49
  return any_msg.TypeName()
36
50
 
@@ -2,7 +2,7 @@
2
2
  # Generated by the protocol buffer compiler. DO NOT EDIT!
3
3
  # NO CHECKED-IN PROTOBUF GENCODE
4
4
  # source: google/protobuf/any.proto
5
- # Protobuf Python Version: 6.30.1
5
+ # Protobuf Python Version: 6.31.0-rc1
6
6
  """Generated protocol buffer code."""
7
7
  from google.protobuf import descriptor as _descriptor
8
8
  from google.protobuf import descriptor_pool as _descriptor_pool
@@ -12,9 +12,9 @@ from google.protobuf.internal import builder as _builder
12
12
  _runtime_version.ValidateProtobufRuntimeVersion(
13
13
  _runtime_version.Domain.PUBLIC,
14
14
  6,
15
- 30,
16
- 1,
17
- '',
15
+ 31,
16
+ 0,
17
+ '-rc1',
18
18
  'google/protobuf/any.proto'
19
19
  )
20
20
  # @@protoc_insertion_point(imports)
@@ -2,7 +2,7 @@
2
2
  # Generated by the protocol buffer compiler. DO NOT EDIT!
3
3
  # NO CHECKED-IN PROTOBUF GENCODE
4
4
  # source: google/protobuf/api.proto
5
- # Protobuf Python Version: 6.30.1
5
+ # Protobuf Python Version: 6.31.0-rc1
6
6
  """Generated protocol buffer code."""
7
7
  from google.protobuf import descriptor as _descriptor
8
8
  from google.protobuf import descriptor_pool as _descriptor_pool
@@ -12,9 +12,9 @@ from google.protobuf.internal import builder as _builder
12
12
  _runtime_version.ValidateProtobufRuntimeVersion(
13
13
  _runtime_version.Domain.PUBLIC,
14
14
  6,
15
- 30,
16
- 1,
17
- '',
15
+ 31,
16
+ 0,
17
+ '-rc1',
18
18
  'google/protobuf/api.proto'
19
19
  )
20
20
  # @@protoc_insertion_point(imports)
@@ -2,7 +2,7 @@
2
2
  # Generated by the protocol buffer compiler. DO NOT EDIT!
3
3
  # NO CHECKED-IN PROTOBUF GENCODE
4
4
  # source: google/protobuf/compiler/plugin.proto
5
- # Protobuf Python Version: 6.30.1
5
+ # Protobuf Python Version: 6.31.0-rc1
6
6
  """Generated protocol buffer code."""
7
7
  from google.protobuf import descriptor as _descriptor
8
8
  from google.protobuf import descriptor_pool as _descriptor_pool
@@ -12,9 +12,9 @@ from google.protobuf.internal import builder as _builder
12
12
  _runtime_version.ValidateProtobufRuntimeVersion(
13
13
  _runtime_version.Domain.PUBLIC,
14
14
  6,
15
- 30,
16
- 1,
17
- '',
15
+ 31,
16
+ 0,
17
+ '-rc1',
18
18
  'google/protobuf/compiler/plugin.proto'
19
19
  )
20
20
  # @@protoc_insertion_point(imports)
@@ -728,6 +728,19 @@ class FieldDescriptor(DescriptorBase):
728
728
  return FieldDescriptor.LABEL_REQUIRED
729
729
  return self._label
730
730
 
731
+ @property
732
+ def is_required(self):
733
+ """Returns if the field is required."""
734
+ return (
735
+ self._GetFeatures().field_presence
736
+ == _FEATURESET_FIELD_PRESENCE_LEGACY_REQUIRED
737
+ )
738
+
739
+ @property
740
+ def is_repeated(self):
741
+ """Returns if the field is repeated."""
742
+ return self._label == FieldDescriptor.LABEL_REPEATED
743
+
731
744
  @property
732
745
  def camelcase_name(self):
733
746
  """Camelcase name of this field.
@@ -746,7 +759,7 @@ class FieldDescriptor(DescriptorBase):
746
759
  Raises:
747
760
  RuntimeError: singular field that is not linked with message nor file.
748
761
  """
749
- if self.label == FieldDescriptor.LABEL_REPEATED:
762
+ if self.is_repeated:
750
763
  return False
751
764
  if (
752
765
  self.cpp_type == FieldDescriptor.CPPTYPE_MESSAGE
@@ -763,7 +776,7 @@ class FieldDescriptor(DescriptorBase):
763
776
  @property
764
777
  def is_packed(self):
765
778
  """Returns if the field is packed."""
766
- if self.label != FieldDescriptor.LABEL_REPEATED:
779
+ if not self.is_repeated:
767
780
  return False
768
781
  field_type = self.type
769
782
  if (field_type == FieldDescriptor.TYPE_STRING or