betterproto2-compiler 0.3.2__py3-none-any.whl → 0.5.0__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.
@@ -4,24 +4,13 @@
4
4
  # This file has been @generated
5
5
 
6
6
  __all__ = (
7
- "Edition",
8
- "ExtensionRangeOptionsVerificationState",
9
- "FeatureSetEnumType",
10
- "FeatureSetFieldPresence",
11
- "FeatureSetJsonFormat",
12
- "FeatureSetMessageEncoding",
13
- "FeatureSetRepeatedFieldEncoding",
14
- "FeatureSetUtf8Validation",
15
7
  "FieldCardinality",
16
8
  "FieldKind",
17
9
  "FieldDescriptorProtoLabel",
18
10
  "FieldDescriptorProtoType",
19
11
  "FieldOptionsCType",
20
12
  "FieldOptionsJsType",
21
- "FieldOptionsOptionRetention",
22
- "FieldOptionsOptionTargetType",
23
13
  "FileOptionsOptimizeMode",
24
- "GeneratedCodeInfoAnnotationSemantic",
25
14
  "MethodOptionsIdempotencyLevel",
26
15
  "NullValue",
27
16
  "Syntax",
@@ -43,15 +32,10 @@ __all__ = (
43
32
  "EnumValueDescriptorProto",
44
33
  "EnumValueOptions",
45
34
  "ExtensionRangeOptions",
46
- "ExtensionRangeOptionsDeclaration",
47
- "FeatureSet",
48
- "FeatureSetDefaults",
49
- "FeatureSetDefaultsFeatureSetEditionDefault",
50
35
  "Field",
51
36
  "FieldDescriptorProto",
52
37
  "FieldMask",
53
38
  "FieldOptions",
54
- "FieldOptionsEditionDefault",
55
39
  "FileDescriptorProto",
56
40
  "FileDescriptorSet",
57
41
  "FileOptions",
@@ -86,124 +70,17 @@ __all__ = (
86
70
  )
87
71
 
88
72
  import datetime
73
+ import re
74
+ import typing
89
75
  import warnings
90
76
  from dataclasses import dataclass
91
- from typing import (
92
- Dict,
93
- List,
94
- Optional,
95
- )
96
77
 
97
78
  import betterproto2
79
+ import dateutil.parser
98
80
 
99
81
  from ...message_pool import default_message_pool
100
82
 
101
- betterproto2.check_compiler_version("0.3.0")
102
-
103
-
104
- class Edition(betterproto2.Enum):
105
- """
106
- The full set of known editions.
107
- """
108
-
109
- UNKNOWN = 0
110
- """
111
- A placeholder for an unknown edition value.
112
- """
113
-
114
- PROTO2 = 998
115
- """
116
- Legacy syntax "editions". These pre-date editions, but behave much like
117
- distinct editions. These can't be used to specify the edition of proto
118
- files, but feature definitions must supply proto2/proto3 defaults for
119
- backwards compatibility.
120
- """
121
-
122
- PROTO3 = 999
123
-
124
- _2023 = 1000
125
- """
126
- Editions that have been released. The specific values are arbitrary and
127
- should not be depended on, but they will always be time-ordered for easy
128
- comparison.
129
- """
130
-
131
- _1_TEST_ONLY = 1
132
- """
133
- Placeholder editions for testing feature resolution. These should not be
134
- used or relyed on outside of tests.
135
- """
136
-
137
- _2_TEST_ONLY = 2
138
-
139
- _99997_TEST_ONLY = 99997
140
-
141
- _99998_TEST_ONLY = 99998
142
-
143
- _99999_TEST_ONLY = 99999
144
-
145
-
146
- class ExtensionRangeOptionsVerificationState(betterproto2.Enum):
147
- """
148
- The verification state of the extension range.
149
- """
150
-
151
- DECLARATION = 0
152
- """
153
- All the extensions of the range must be declared.
154
- """
155
-
156
- UNVERIFIED = 1
157
-
158
-
159
- class FeatureSetEnumType(betterproto2.Enum):
160
- ENUM_TYPE_UNKNOWN = 0
161
-
162
- OPEN = 1
163
-
164
- CLOSED = 2
165
-
166
-
167
- class FeatureSetFieldPresence(betterproto2.Enum):
168
- FIELD_PRESENCE_UNKNOWN = 0
169
-
170
- EXPLICIT = 1
171
-
172
- IMPLICIT = 2
173
-
174
- LEGACY_REQUIRED = 3
175
-
176
-
177
- class FeatureSetJsonFormat(betterproto2.Enum):
178
- JSON_FORMAT_UNKNOWN = 0
179
-
180
- ALLOW = 1
181
-
182
- LEGACY_BEST_EFFORT = 2
183
-
184
-
185
- class FeatureSetMessageEncoding(betterproto2.Enum):
186
- MESSAGE_ENCODING_UNKNOWN = 0
187
-
188
- LENGTH_PREFIXED = 1
189
-
190
- DELIMITED = 2
191
-
192
-
193
- class FeatureSetRepeatedFieldEncoding(betterproto2.Enum):
194
- REPEATED_FIELD_ENCODING_UNKNOWN = 0
195
-
196
- PACKED = 1
197
-
198
- EXPANDED = 2
199
-
200
-
201
- class FeatureSetUtf8Validation(betterproto2.Enum):
202
- UTF8_VALIDATION_UNKNOWN = 0
203
-
204
- NONE = 1
205
-
206
- VERIFY = 2
83
+ betterproto2.check_compiler_version("0.5.0")
207
84
 
208
85
 
209
86
  class FieldCardinality(betterproto2.Enum):
@@ -339,14 +216,9 @@ class FieldDescriptorProtoLabel(betterproto2.Enum):
339
216
  0 is reserved for errors
340
217
  """
341
218
 
342
- LABEL_REPEATED = 3
343
-
344
219
  LABEL_REQUIRED = 2
345
- """
346
- The required label is only allowed in google.protobuf. In proto3 and Editions
347
- it's explicitly prohibited. In Editions, the `field_presence` feature
348
- can be used to get this behavior.
349
- """
220
+
221
+ LABEL_REPEATED = 3
350
222
 
351
223
 
352
224
  class FieldDescriptorProtoType(betterproto2.Enum):
@@ -383,10 +255,9 @@ class FieldDescriptorProtoType(betterproto2.Enum):
383
255
  TYPE_GROUP = 10
384
256
  """
385
257
  Tag-delimited aggregate.
386
- Group type is deprecated and not supported after google.protobuf. However, Proto3
258
+ Group type is deprecated and not supported in proto3. However, Proto3
387
259
  implementations should still be able to parse the group wire format and
388
- treat group fields as unknown fields. In Editions, the group wire format
389
- can be enabled via the `message_encoding` feature.
260
+ treat group fields as unknown fields.
390
261
  """
391
262
 
392
263
  TYPE_MESSAGE = 11
@@ -425,14 +296,6 @@ class FieldOptionsCType(betterproto2.Enum):
425
296
  """
426
297
 
427
298
  CORD = 1
428
- """
429
- The option [ctype=CORD] may be applied to a non-repeated field of type
430
- "bytes". It indicates that in C++, the data should be stored in a Cord
431
- instead of a string. For very large strings, this may reduce memory
432
- fragmentation. It may also allow better performance when parsing from a
433
- Cord, or when parsing with aliasing enabled, as the parsed Cord may then
434
- alias the original buffer.
435
- """
436
299
 
437
300
  STRING_PIECE = 2
438
301
 
@@ -454,49 +317,6 @@ class FieldOptionsJsType(betterproto2.Enum):
454
317
  """
455
318
 
456
319
 
457
- class FieldOptionsOptionRetention(betterproto2.Enum):
458
- """
459
- If set to RETENTION_SOURCE, the option will be omitted from the binary.
460
- Note: as of January 2023, support for this is in progress and does not yet
461
- have an effect (b/264593489).
462
- """
463
-
464
- RETENTION_UNKNOWN = 0
465
-
466
- RETENTION_RUNTIME = 1
467
-
468
- RETENTION_SOURCE = 2
469
-
470
-
471
- class FieldOptionsOptionTargetType(betterproto2.Enum):
472
- """
473
- This indicates the types of entities that the field may apply to when used
474
- as an option. If it is unset, then the field may be freely used as an
475
- option on any kind of entity. Note: as of January 2023, support for this is
476
- in progress and does not yet have an effect (b/264593489).
477
- """
478
-
479
- TARGET_TYPE_UNKNOWN = 0
480
-
481
- TARGET_TYPE_FILE = 1
482
-
483
- TARGET_TYPE_EXTENSION_RANGE = 2
484
-
485
- TARGET_TYPE_MESSAGE = 3
486
-
487
- TARGET_TYPE_FIELD = 4
488
-
489
- TARGET_TYPE_ONEOF = 5
490
-
491
- TARGET_TYPE_ENUM = 6
492
-
493
- TARGET_TYPE_ENUM_ENTRY = 7
494
-
495
- TARGET_TYPE_SERVICE = 8
496
-
497
- TARGET_TYPE_METHOD = 9
498
-
499
-
500
320
  class FileOptionsOptimizeMode(betterproto2.Enum):
501
321
  """
502
322
  Generated classes can be optimized for speed or code size.
@@ -520,28 +340,6 @@ class FileOptionsOptimizeMode(betterproto2.Enum):
520
340
  """
521
341
 
522
342
 
523
- class GeneratedCodeInfoAnnotationSemantic(betterproto2.Enum):
524
- """
525
- Represents the identified object's effect on the element in the original
526
- .proto file.
527
- """
528
-
529
- NONE = 0
530
- """
531
- There is no effect or the effect is indescribable.
532
- """
533
-
534
- SET = 1
535
- """
536
- The element is set or otherwise mutated.
537
- """
538
-
539
- ALIAS = 2
540
- """
541
- An alias to the element is returned.
542
- """
543
-
544
-
545
343
  class MethodOptionsIdempotencyLevel(betterproto2.Enum):
546
344
  """
547
345
  Is this method side-effect-free (or safe in HTTP parlance), or idempotent,
@@ -567,7 +365,7 @@ class NullValue(betterproto2.Enum):
567
365
  `NullValue` is a singleton enumeration to represent the null value for the
568
366
  `Value` type union.
569
367
 
570
- The JSON representation for `NullValue` is JSON `null`.
368
+ The JSON representation for `NullValue` is JSON `null`.
571
369
  """
572
370
 
573
371
  _ = 0
@@ -591,11 +389,6 @@ class Syntax(betterproto2.Enum):
591
389
  Syntax `proto3`.
592
390
  """
593
391
 
594
- EDITIONS = 2
595
- """
596
- Syntax `editions`.
597
- """
598
-
599
392
 
600
393
  @dataclass(eq=False, repr=False)
601
394
  class Any(betterproto2.Message):
@@ -624,12 +417,8 @@ class Any(betterproto2.Message):
624
417
  if (any.is(Foo.class)) {
625
418
  foo = any.unpack(Foo.class);
626
419
  }
627
- // or ...
628
- if (any.isSameTypeAs(Foo.getDefaultInstance())) {
629
- foo = any.unpack(Foo.getDefaultInstance());
630
- }
631
420
 
632
- Example 3: Pack and unpack a message in Python.
421
+ Example 3: Pack and unpack a message in Python.
633
422
 
634
423
  foo = Foo(...)
635
424
  any = Any()
@@ -639,7 +428,7 @@ class Any(betterproto2.Message):
639
428
  any.Unpack(foo)
640
429
  ...
641
430
 
642
- Example 4: Pack and unpack a message in Go
431
+ Example 4: Pack and unpack a message in Go
643
432
 
644
433
  foo := &pb.Foo{...}
645
434
  any, err := anypb.New(foo)
@@ -659,7 +448,7 @@ class Any(betterproto2.Message):
659
448
  name "y.z".
660
449
 
661
450
  JSON
662
- ====
451
+
663
452
  The JSON representation of an `Any` value uses the regular
664
453
  representation of the deserialized, embedded message, with an
665
454
  additional field `@type` which contains the type URL. Example:
@@ -712,8 +501,7 @@ class Any(betterproto2.Message):
712
501
 
713
502
  Note: this functionality is not currently available in the official
714
503
  protobuf release, and it is not used for type URLs beginning with
715
- type.googleapis.com. As of May 2023, there are no widely used type server
716
- implementations and no plans to implement one.
504
+ type.googleapis.com.
717
505
 
718
506
  Schemes other than `http`, `https` (or the empty scheme) might be
719
507
  used with implementation specific semantics.
@@ -724,6 +512,53 @@ class Any(betterproto2.Message):
724
512
  Must be a valid serialized protocol buffer of the above specified type.
725
513
  """
726
514
 
515
+ def pack(self, message: betterproto2.Message, message_pool: "betterproto2.MessagePool | None" = None) -> None:
516
+ """
517
+ Pack the given message in the `Any` object.
518
+
519
+ The message type must be registered in the message pool, which is done automatically when the module defining
520
+ the message type is imported.
521
+ """
522
+ message_pool = message_pool or default_message_pool
523
+
524
+ self.type_url = message_pool.type_to_url[type(message)]
525
+ self.value = bytes(message)
526
+
527
+ def unpack(self, message_pool: "betterproto2.MessagePool | None" = None) -> betterproto2.Message | None:
528
+ """
529
+ Return the message packed inside the `Any` object.
530
+
531
+ The target message type must be registered in the message pool, which is done automatically when the module
532
+ defining the message type is imported.
533
+ """
534
+ if not self.type_url:
535
+ return None
536
+
537
+ message_pool = message_pool or default_message_pool
538
+
539
+ try:
540
+ message_type = message_pool.url_to_type[self.type_url]
541
+ except KeyError:
542
+ raise TypeError(f"Can't unpack unregistered type: {self.type_url}")
543
+
544
+ return message_type().parse(self.value)
545
+
546
+ def to_dict(self, **kwargs) -> dict[str, typing.Any]:
547
+ # TODO allow passing a message pool to `to_dict`
548
+ output: dict[str, typing.Any] = {"@type": self.type_url}
549
+
550
+ value = self.unpack()
551
+
552
+ if value is None:
553
+ return output
554
+
555
+ if type(value).to_dict == betterproto2.Message.to_dict:
556
+ output.update(value.to_dict(**kwargs))
557
+ else:
558
+ output["value"] = value.to_dict(**kwargs)
559
+
560
+ return output
561
+
727
562
 
728
563
  default_message_pool.register_message("google.protobuf", "Any", Any)
729
564
 
@@ -748,12 +583,12 @@ class Api(betterproto2.Message):
748
583
  followed by the interface's simple name.
749
584
  """
750
585
 
751
- methods: "List[Method]" = betterproto2.field(2, betterproto2.TYPE_MESSAGE, repeated=True)
586
+ methods: "list[Method]" = betterproto2.field(2, betterproto2.TYPE_MESSAGE, repeated=True)
752
587
  """
753
588
  The methods of this interface, in unspecified order.
754
589
  """
755
590
 
756
- options: "List[Option]" = betterproto2.field(3, betterproto2.TYPE_MESSAGE, repeated=True)
591
+ options: "list[Option]" = betterproto2.field(3, betterproto2.TYPE_MESSAGE, repeated=True)
757
592
  """
758
593
  Any metadata attached to the interface.
759
594
  """
@@ -781,13 +616,13 @@ class Api(betterproto2.Message):
781
616
  experimental, non-GA interfaces.
782
617
  """
783
618
 
784
- source_context: "Optional[SourceContext]" = betterproto2.field(5, betterproto2.TYPE_MESSAGE, optional=True)
619
+ source_context: "SourceContext | None" = betterproto2.field(5, betterproto2.TYPE_MESSAGE, optional=True)
785
620
  """
786
621
  Source context for the protocol buffer service represented by this
787
622
  message.
788
623
  """
789
624
 
790
- mixins: "List[Mixin]" = betterproto2.field(6, betterproto2.TYPE_MESSAGE, repeated=True)
625
+ mixins: "list[Mixin]" = betterproto2.field(6, betterproto2.TYPE_MESSAGE, repeated=True)
791
626
  """
792
627
  Included interfaces. See [Mixin][].
793
628
  """
@@ -814,6 +649,28 @@ class BoolValue(betterproto2.Message):
814
649
  The bool value.
815
650
  """
816
651
 
652
+ @classmethod
653
+ def from_dict(cls, value):
654
+ if isinstance(value, bool):
655
+ return BoolValue(value=value)
656
+ return super().from_dict(value)
657
+
658
+ def to_dict(
659
+ self,
660
+ *,
661
+ output_format: betterproto2.OutputFormat = betterproto2.OutputFormat.PROTO_JSON,
662
+ casing: betterproto2.Casing = betterproto2.Casing.CAMEL,
663
+ include_default_values: bool = False,
664
+ ) -> dict[str, typing.Any] | typing.Any:
665
+ return self.value
666
+
667
+ @staticmethod
668
+ def from_wrapped(wrapped: bool) -> "BoolValue":
669
+ return BoolValue(value=wrapped)
670
+
671
+ def to_wrapped(self) -> bool:
672
+ return self.value
673
+
817
674
 
818
675
  default_message_pool.register_message("google.protobuf", "BoolValue", BoolValue)
819
676
 
@@ -831,6 +688,28 @@ class BytesValue(betterproto2.Message):
831
688
  The bytes value.
832
689
  """
833
690
 
691
+ @classmethod
692
+ def from_dict(cls, value):
693
+ if isinstance(value, bytes):
694
+ return BytesValue(value=value)
695
+ return super().from_dict(value)
696
+
697
+ def to_dict(
698
+ self,
699
+ *,
700
+ output_format: betterproto2.OutputFormat = betterproto2.OutputFormat.PROTO_JSON,
701
+ casing: betterproto2.Casing = betterproto2.Casing.CAMEL,
702
+ include_default_values: bool = False,
703
+ ) -> dict[str, typing.Any] | typing.Any:
704
+ return self.value
705
+
706
+ @staticmethod
707
+ def from_wrapped(wrapped: bytes) -> "BytesValue":
708
+ return BytesValue(value=wrapped)
709
+
710
+ def to_wrapped(self) -> bytes:
711
+ return self.value
712
+
834
713
 
835
714
  default_message_pool.register_message("google.protobuf", "BytesValue", BytesValue)
836
715
 
@@ -843,27 +722,27 @@ class DescriptorProto(betterproto2.Message):
843
722
 
844
723
  name: "str" = betterproto2.field(1, betterproto2.TYPE_STRING)
845
724
 
846
- field: "List[FieldDescriptorProto]" = betterproto2.field(2, betterproto2.TYPE_MESSAGE, repeated=True)
725
+ field: "list[FieldDescriptorProto]" = betterproto2.field(2, betterproto2.TYPE_MESSAGE, repeated=True)
847
726
 
848
- extension: "List[FieldDescriptorProto]" = betterproto2.field(6, betterproto2.TYPE_MESSAGE, repeated=True)
727
+ extension: "list[FieldDescriptorProto]" = betterproto2.field(6, betterproto2.TYPE_MESSAGE, repeated=True)
849
728
 
850
- nested_type: "List[DescriptorProto]" = betterproto2.field(3, betterproto2.TYPE_MESSAGE, repeated=True)
729
+ nested_type: "list[DescriptorProto]" = betterproto2.field(3, betterproto2.TYPE_MESSAGE, repeated=True)
851
730
 
852
- enum_type: "List[EnumDescriptorProto]" = betterproto2.field(4, betterproto2.TYPE_MESSAGE, repeated=True)
731
+ enum_type: "list[EnumDescriptorProto]" = betterproto2.field(4, betterproto2.TYPE_MESSAGE, repeated=True)
853
732
 
854
- extension_range: "List[DescriptorProtoExtensionRange]" = betterproto2.field(
733
+ extension_range: "list[DescriptorProtoExtensionRange]" = betterproto2.field(
855
734
  5, betterproto2.TYPE_MESSAGE, repeated=True
856
735
  )
857
736
 
858
- oneof_decl: "List[OneofDescriptorProto]" = betterproto2.field(8, betterproto2.TYPE_MESSAGE, repeated=True)
737
+ oneof_decl: "list[OneofDescriptorProto]" = betterproto2.field(8, betterproto2.TYPE_MESSAGE, repeated=True)
859
738
 
860
- options: "Optional[MessageOptions]" = betterproto2.field(7, betterproto2.TYPE_MESSAGE, optional=True)
739
+ options: "MessageOptions | None" = betterproto2.field(7, betterproto2.TYPE_MESSAGE, optional=True)
861
740
 
862
- reserved_range: "List[DescriptorProtoReservedRange]" = betterproto2.field(
741
+ reserved_range: "list[DescriptorProtoReservedRange]" = betterproto2.field(
863
742
  9, betterproto2.TYPE_MESSAGE, repeated=True
864
743
  )
865
744
 
866
- reserved_name: "List[str]" = betterproto2.field(10, betterproto2.TYPE_STRING, repeated=True)
745
+ reserved_name: "list[str]" = betterproto2.field(10, betterproto2.TYPE_STRING, repeated=True)
867
746
  """
868
747
  Reserved field names, which may not be used by fields in the same message.
869
748
  A given name may only be reserved once.
@@ -885,7 +764,7 @@ class DescriptorProtoExtensionRange(betterproto2.Message):
885
764
  Exclusive.
886
765
  """
887
766
 
888
- options: "Optional[ExtensionRangeOptions]" = betterproto2.field(3, betterproto2.TYPE_MESSAGE, optional=True)
767
+ options: "ExtensionRangeOptions | None" = betterproto2.field(3, betterproto2.TYPE_MESSAGE, optional=True)
889
768
 
890
769
 
891
770
  default_message_pool.register_message(
@@ -928,6 +807,28 @@ class DoubleValue(betterproto2.Message):
928
807
  The double value.
929
808
  """
930
809
 
810
+ @classmethod
811
+ def from_dict(cls, value):
812
+ if isinstance(value, float):
813
+ return DoubleValue(value=value)
814
+ return super().from_dict(value)
815
+
816
+ def to_dict(
817
+ self,
818
+ *,
819
+ output_format: betterproto2.OutputFormat = betterproto2.OutputFormat.PROTO_JSON,
820
+ casing: betterproto2.Casing = betterproto2.Casing.CAMEL,
821
+ include_default_values: bool = False,
822
+ ) -> dict[str, typing.Any] | typing.Any:
823
+ return self.value
824
+
825
+ @staticmethod
826
+ def from_wrapped(wrapped: float) -> "DoubleValue":
827
+ return DoubleValue(value=wrapped)
828
+
829
+ def to_wrapped(self) -> float:
830
+ return self.value
831
+
931
832
 
932
833
  default_message_pool.register_message("google.protobuf", "DoubleValue", DoubleValue)
933
834
 
@@ -1032,6 +933,45 @@ class Duration(betterproto2.Message):
1032
933
  parts[1] = f"{parts[1]}0"
1033
934
  return f"{'.'.join(parts)}s"
1034
935
 
936
+ @classmethod
937
+ def from_dict(cls, value):
938
+ if isinstance(value, str):
939
+ if not re.match(r"^\d+(\.\d+)?s$", value):
940
+ raise ValueError(f"Invalid duration string: {value}")
941
+
942
+ seconds = float(value[:-1])
943
+ return Duration(seconds=int(seconds), nanos=int((seconds - int(seconds)) * 1e9))
944
+
945
+ return super().from_dict(value)
946
+
947
+ def to_dict(
948
+ self,
949
+ *,
950
+ output_format: betterproto2.OutputFormat = betterproto2.OutputFormat.PROTO_JSON,
951
+ casing: betterproto2.Casing = betterproto2.Casing.CAMEL,
952
+ include_default_values: bool = False,
953
+ ) -> dict[str, typing.Any] | typing.Any:
954
+ # If the output format is PYTHON, we should have kept the wrapped type without building the real class
955
+ assert output_format == betterproto2.OutputFormat.PROTO_JSON
956
+
957
+ assert 0 <= self.nanos < 1e9
958
+
959
+ if self.nanos == 0:
960
+ return f"{self.seconds}s"
961
+
962
+ nanos = f"{self.nanos:09d}".rstrip("0")
963
+ if len(nanos) < 3:
964
+ nanos += "0" * (3 - len(nanos))
965
+
966
+ return f"{self.seconds}.{nanos}s"
967
+
968
+ @staticmethod
969
+ def from_wrapped(wrapped: datetime.timedelta) -> "Duration":
970
+ return Duration.from_timedelta(wrapped)
971
+
972
+ def to_wrapped(self) -> datetime.timedelta:
973
+ return self.to_timedelta()
974
+
1035
975
 
1036
976
  default_message_pool.register_message("google.protobuf", "Duration", Duration)
1037
977
 
@@ -1065,19 +1005,17 @@ class Enum(betterproto2.Message):
1065
1005
  Enum type name.
1066
1006
  """
1067
1007
 
1068
- enumvalue: "List[EnumValue]" = betterproto2.field(
1069
- 2, betterproto2.TYPE_MESSAGE, wraps=betterproto2.TYPE_ENUM, repeated=True
1070
- )
1008
+ enumvalue: "list[EnumValue]" = betterproto2.field(2, betterproto2.TYPE_MESSAGE, repeated=True)
1071
1009
  """
1072
1010
  Enum value definitions.
1073
1011
  """
1074
1012
 
1075
- options: "List[Option]" = betterproto2.field(3, betterproto2.TYPE_MESSAGE, repeated=True)
1013
+ options: "list[Option]" = betterproto2.field(3, betterproto2.TYPE_MESSAGE, repeated=True)
1076
1014
  """
1077
1015
  Protocol buffer options.
1078
1016
  """
1079
1017
 
1080
- source_context: "Optional[SourceContext]" = betterproto2.field(4, betterproto2.TYPE_MESSAGE, optional=True)
1018
+ source_context: "SourceContext | None" = betterproto2.field(4, betterproto2.TYPE_MESSAGE, optional=True)
1081
1019
  """
1082
1020
  The source context.
1083
1021
  """
@@ -1087,11 +1025,6 @@ class Enum(betterproto2.Message):
1087
1025
  The source syntax.
1088
1026
  """
1089
1027
 
1090
- edition: "str" = betterproto2.field(6, betterproto2.TYPE_STRING)
1091
- """
1092
- The source edition string, only valid when syntax is SYNTAX_EDITIONS.
1093
- """
1094
-
1095
1028
 
1096
1029
  default_message_pool.register_message("google.protobuf", "Enum", Enum)
1097
1030
 
@@ -1104,11 +1037,11 @@ class EnumDescriptorProto(betterproto2.Message):
1104
1037
 
1105
1038
  name: "str" = betterproto2.field(1, betterproto2.TYPE_STRING)
1106
1039
 
1107
- value: "List[EnumValueDescriptorProto]" = betterproto2.field(2, betterproto2.TYPE_MESSAGE, repeated=True)
1040
+ value: "list[EnumValueDescriptorProto]" = betterproto2.field(2, betterproto2.TYPE_MESSAGE, repeated=True)
1108
1041
 
1109
- options: "Optional[EnumOptions]" = betterproto2.field(3, betterproto2.TYPE_MESSAGE, optional=True)
1042
+ options: "EnumOptions | None" = betterproto2.field(3, betterproto2.TYPE_MESSAGE, optional=True)
1110
1043
 
1111
- reserved_range: "List[EnumDescriptorProtoEnumReservedRange]" = betterproto2.field(
1044
+ reserved_range: "list[EnumDescriptorProtoEnumReservedRange]" = betterproto2.field(
1112
1045
  4, betterproto2.TYPE_MESSAGE, repeated=True
1113
1046
  )
1114
1047
  """
@@ -1117,7 +1050,7 @@ class EnumDescriptorProto(betterproto2.Message):
1117
1050
  overlap.
1118
1051
  """
1119
1052
 
1120
- reserved_name: "List[str]" = betterproto2.field(5, betterproto2.TYPE_STRING, repeated=True)
1053
+ reserved_name: "list[str]" = betterproto2.field(5, betterproto2.TYPE_STRING, repeated=True)
1121
1054
  """
1122
1055
  Reserved enum value names, which may not be reused. A given name may only
1123
1056
  be reserved once.
@@ -1170,33 +1103,13 @@ class EnumOptions(betterproto2.Message):
1170
1103
  is a formalization for deprecating enums.
1171
1104
  """
1172
1105
 
1173
- deprecated_legacy_json_field_conflicts: "bool" = betterproto2.field(6, betterproto2.TYPE_BOOL)
1174
- """
1175
- Enable the legacy handling of JSON field name conflicts. This lowercases
1176
- and strips underscored from the fields before comparison in proto3 only.
1177
- The new behavior takes `json_name` into account and applies to proto2 as
1178
- well.
1179
- TODO Remove this legacy behavior once downstream teams have
1180
- had time to migrate.
1181
- """
1182
-
1183
- features: "Optional[FeatureSet]" = betterproto2.field(7, betterproto2.TYPE_MESSAGE, optional=True)
1184
- """
1185
- Any features defined in the specific edition.
1186
- """
1187
-
1188
- uninterpreted_option: "List[UninterpretedOption]" = betterproto2.field(
1106
+ uninterpreted_option: "list[UninterpretedOption]" = betterproto2.field(
1189
1107
  999, betterproto2.TYPE_MESSAGE, repeated=True
1190
1108
  )
1191
1109
  """
1192
1110
  The parser stores options it doesn't recognize here. See above.
1193
1111
  """
1194
1112
 
1195
- def __post_init__(self) -> None:
1196
- super().__post_init__()
1197
- if self.is_set("deprecated_legacy_json_field_conflicts"):
1198
- warnings.warn("EnumOptions.deprecated_legacy_json_field_conflicts is deprecated", DeprecationWarning)
1199
-
1200
1113
 
1201
1114
  default_message_pool.register_message("google.protobuf", "EnumOptions", EnumOptions)
1202
1115
 
@@ -1217,7 +1130,7 @@ class EnumValue(betterproto2.Message):
1217
1130
  Enum value number.
1218
1131
  """
1219
1132
 
1220
- options: "List[Option]" = betterproto2.field(3, betterproto2.TYPE_MESSAGE, repeated=True)
1133
+ options: "list[Option]" = betterproto2.field(3, betterproto2.TYPE_MESSAGE, repeated=True)
1221
1134
  """
1222
1135
  Protocol buffer options.
1223
1136
  """
@@ -1236,7 +1149,7 @@ class EnumValueDescriptorProto(betterproto2.Message):
1236
1149
 
1237
1150
  number: "int" = betterproto2.field(2, betterproto2.TYPE_INT32)
1238
1151
 
1239
- options: "Optional[EnumValueOptions]" = betterproto2.field(3, betterproto2.TYPE_MESSAGE, optional=True)
1152
+ options: "EnumValueOptions | None" = betterproto2.field(3, betterproto2.TYPE_MESSAGE, optional=True)
1240
1153
 
1241
1154
 
1242
1155
  default_message_pool.register_message("google.protobuf", "EnumValueDescriptorProto", EnumValueDescriptorProto)
@@ -1252,19 +1165,7 @@ class EnumValueOptions(betterproto2.Message):
1252
1165
  this is a formalization for deprecating enum values.
1253
1166
  """
1254
1167
 
1255
- features: "Optional[FeatureSet]" = betterproto2.field(2, betterproto2.TYPE_MESSAGE, optional=True)
1256
- """
1257
- Any features defined in the specific edition.
1258
- """
1259
-
1260
- debug_redact: "bool" = betterproto2.field(3, betterproto2.TYPE_BOOL)
1261
- """
1262
- Indicate that fields annotated with this enum value should not be printed
1263
- out when using debug formats, e.g. when the field contains sensitive
1264
- credentials.
1265
- """
1266
-
1267
- uninterpreted_option: "List[UninterpretedOption]" = betterproto2.field(
1168
+ uninterpreted_option: "list[UninterpretedOption]" = betterproto2.field(
1268
1169
  999, betterproto2.TYPE_MESSAGE, repeated=True
1269
1170
  )
1270
1171
  """
@@ -1277,173 +1178,17 @@ default_message_pool.register_message("google.protobuf", "EnumValueOptions", Enu
1277
1178
 
1278
1179
  @dataclass(eq=False, repr=False)
1279
1180
  class ExtensionRangeOptions(betterproto2.Message):
1280
- uninterpreted_option: "List[UninterpretedOption]" = betterproto2.field(
1181
+ uninterpreted_option: "list[UninterpretedOption]" = betterproto2.field(
1281
1182
  999, betterproto2.TYPE_MESSAGE, repeated=True
1282
1183
  )
1283
1184
  """
1284
1185
  The parser stores options it doesn't recognize here. See above.
1285
1186
  """
1286
1187
 
1287
- declaration: "List[ExtensionRangeOptionsDeclaration]" = betterproto2.field(
1288
- 2, betterproto2.TYPE_MESSAGE, repeated=True
1289
- )
1290
- """
1291
- For external users: DO NOT USE. We are in the process of open sourcing
1292
- extension declaration and executing internal cleanups before it can be
1293
- used externally.
1294
- """
1295
-
1296
- features: "Optional[FeatureSet]" = betterproto2.field(50, betterproto2.TYPE_MESSAGE, optional=True)
1297
- """
1298
- Any features defined in the specific edition.
1299
- """
1300
-
1301
- verification: "ExtensionRangeOptionsVerificationState" = betterproto2.field(
1302
- 3, betterproto2.TYPE_ENUM, default_factory=lambda: ExtensionRangeOptionsVerificationState(0)
1303
- )
1304
- """
1305
- The verification state of the range.
1306
- TODO: flip the default to DECLARATION once all empty ranges
1307
- are marked as UNVERIFIED.
1308
- """
1309
-
1310
1188
 
1311
1189
  default_message_pool.register_message("google.protobuf", "ExtensionRangeOptions", ExtensionRangeOptions)
1312
1190
 
1313
1191
 
1314
- @dataclass(eq=False, repr=False)
1315
- class ExtensionRangeOptionsDeclaration(betterproto2.Message):
1316
- number: "int" = betterproto2.field(1, betterproto2.TYPE_INT32)
1317
- """
1318
- The extension number declared within the extension range.
1319
- """
1320
-
1321
- full_name: "str" = betterproto2.field(2, betterproto2.TYPE_STRING)
1322
- """
1323
- The fully-qualified name of the extension field. There must be a leading
1324
- dot in front of the full name.
1325
- """
1326
-
1327
- type: "str" = betterproto2.field(3, betterproto2.TYPE_STRING)
1328
- """
1329
- The fully-qualified type name of the extension field. Unlike
1330
- Metadata.type, Declaration.type must have a leading dot for messages
1331
- and enums.
1332
- """
1333
-
1334
- reserved: "bool" = betterproto2.field(5, betterproto2.TYPE_BOOL)
1335
- """
1336
- If true, indicates that the number is reserved in the extension range,
1337
- and any extension field with the number will fail to compile. Set this
1338
- when a declared extension field is deleted.
1339
- """
1340
-
1341
- repeated: "bool" = betterproto2.field(6, betterproto2.TYPE_BOOL)
1342
- """
1343
- If true, indicates that the extension must be defined as repeated.
1344
- Otherwise the extension must be defined as optional.
1345
- """
1346
-
1347
-
1348
- default_message_pool.register_message(
1349
- "google.protobuf", "ExtensionRangeOptions.Declaration", ExtensionRangeOptionsDeclaration
1350
- )
1351
-
1352
-
1353
- @dataclass(eq=False, repr=False)
1354
- class FeatureSet(betterproto2.Message):
1355
- """
1356
- ===================================================================
1357
- Features
1358
-
1359
- TODO Enums in C++ gencode (and potentially other languages) are
1360
- not well scoped. This means that each of the feature enums below can clash
1361
- with each other. The short names we've chosen maximize call-site
1362
- readability, but leave us very open to this scenario. A future feature will
1363
- be designed and implemented to handle this, hopefully before we ever hit a
1364
- conflict here.
1365
- """
1366
-
1367
- field_presence: "FeatureSetFieldPresence" = betterproto2.field(
1368
- 1, betterproto2.TYPE_ENUM, default_factory=lambda: FeatureSetFieldPresence(0)
1369
- )
1370
-
1371
- enum_type: "FeatureSetEnumType" = betterproto2.field(
1372
- 2, betterproto2.TYPE_ENUM, default_factory=lambda: FeatureSetEnumType(0)
1373
- )
1374
-
1375
- repeated_field_encoding: "FeatureSetRepeatedFieldEncoding" = betterproto2.field(
1376
- 3, betterproto2.TYPE_ENUM, default_factory=lambda: FeatureSetRepeatedFieldEncoding(0)
1377
- )
1378
-
1379
- utf8_validation: "FeatureSetUtf8Validation" = betterproto2.field(
1380
- 4, betterproto2.TYPE_ENUM, default_factory=lambda: FeatureSetUtf8Validation(0)
1381
- )
1382
-
1383
- message_encoding: "FeatureSetMessageEncoding" = betterproto2.field(
1384
- 5, betterproto2.TYPE_ENUM, default_factory=lambda: FeatureSetMessageEncoding(0)
1385
- )
1386
-
1387
- json_format: "FeatureSetJsonFormat" = betterproto2.field(
1388
- 6, betterproto2.TYPE_ENUM, default_factory=lambda: FeatureSetJsonFormat(0)
1389
- )
1390
-
1391
-
1392
- default_message_pool.register_message("google.protobuf", "FeatureSet", FeatureSet)
1393
-
1394
-
1395
- @dataclass(eq=False, repr=False)
1396
- class FeatureSetDefaults(betterproto2.Message):
1397
- """
1398
- A compiled specification for the defaults of a set of features. These
1399
- messages are generated from FeatureSet extensions and can be used to seed
1400
- feature resolution. The resolution with this object becomes a simple search
1401
- for the closest matching edition, followed by proto merges.
1402
- """
1403
-
1404
- defaults: "List[FeatureSetDefaultsFeatureSetEditionDefault]" = betterproto2.field(
1405
- 1, betterproto2.TYPE_MESSAGE, repeated=True
1406
- )
1407
-
1408
- minimum_edition: "Edition" = betterproto2.field(
1409
- 4, betterproto2.TYPE_ENUM, default_factory=lambda: Edition(0)
1410
- )
1411
- """
1412
- The minimum supported edition (inclusive) when this was constructed.
1413
- Editions before this will not have defaults.
1414
- """
1415
-
1416
- maximum_edition: "Edition" = betterproto2.field(
1417
- 5, betterproto2.TYPE_ENUM, default_factory=lambda: Edition(0)
1418
- )
1419
- """
1420
- The maximum known edition (inclusive) when this was constructed. Editions
1421
- after this will not have reliable defaults.
1422
- """
1423
-
1424
-
1425
- default_message_pool.register_message("google.protobuf", "FeatureSetDefaults", FeatureSetDefaults)
1426
-
1427
-
1428
- @dataclass(eq=False, repr=False)
1429
- class FeatureSetDefaultsFeatureSetEditionDefault(betterproto2.Message):
1430
- """
1431
- A map from every known edition with a unique set of defaults to its
1432
- defaults. Not all editions may be contained here. For a given edition,
1433
- the defaults at the closest matching edition ordered at or before it should
1434
- be used. This field must be in strict ascending order by edition.
1435
- """
1436
-
1437
- edition: "Edition" = betterproto2.field(3, betterproto2.TYPE_ENUM, default_factory=lambda: Edition(0))
1438
-
1439
- features: "Optional[FeatureSet]" = betterproto2.field(2, betterproto2.TYPE_MESSAGE, optional=True)
1440
-
1441
-
1442
- default_message_pool.register_message(
1443
- "google.protobuf", "FeatureSetDefaults.FeatureSetEditionDefault", FeatureSetDefaultsFeatureSetEditionDefault
1444
- )
1445
-
1446
-
1447
1192
  @dataclass(eq=False, repr=False)
1448
1193
  class Field(betterproto2.Message):
1449
1194
  """
@@ -1489,7 +1234,7 @@ class Field(betterproto2.Message):
1489
1234
  Whether to use alternative packed wire representation.
1490
1235
  """
1491
1236
 
1492
- options: "List[Option]" = betterproto2.field(9, betterproto2.TYPE_MESSAGE, repeated=True)
1237
+ options: "list[Option]" = betterproto2.field(9, betterproto2.TYPE_MESSAGE, repeated=True)
1493
1238
  """
1494
1239
  The protocol buffer options.
1495
1240
  """
@@ -1567,7 +1312,7 @@ class FieldDescriptorProto(betterproto2.Message):
1567
1312
  it to camelCase.
1568
1313
  """
1569
1314
 
1570
- options: "Optional[FieldOptions]" = betterproto2.field(8, betterproto2.TYPE_MESSAGE, optional=True)
1315
+ options: "FieldOptions | None" = betterproto2.field(8, betterproto2.TYPE_MESSAGE, optional=True)
1571
1316
 
1572
1317
  proto3_optional: "bool" = betterproto2.field(17, betterproto2.TYPE_BOOL)
1573
1318
  """
@@ -1801,7 +1546,7 @@ class FieldMask(betterproto2.Message):
1801
1546
  `INVALID_ARGUMENT` error if any path is unmappable.
1802
1547
  """
1803
1548
 
1804
- paths: "List[str]" = betterproto2.field(1, betterproto2.TYPE_STRING, repeated=True)
1549
+ paths: "list[str]" = betterproto2.field(1, betterproto2.TYPE_STRING, repeated=True)
1805
1550
  """
1806
1551
  The set of field mask paths.
1807
1552
  """
@@ -1818,10 +1563,8 @@ class FieldOptions(betterproto2.Message):
1818
1563
  """
1819
1564
  The ctype option instructs the C++ code generator to use a different
1820
1565
  representation of the field than it normally would. See the specific
1821
- options below. This option is only implemented to support use of
1822
- [ctype=CORD] and [ctype=STRING] (the default) on non-repeated fields of
1823
- type "bytes" in the open source release -- sorry, we'll try to include
1824
- other types in a future version!
1566
+ options below. This option is not yet implemented in the open source
1567
+ release -- sorry, we'll try to include it in a future version!
1825
1568
  """
1826
1569
 
1827
1570
  packed: "bool" = betterproto2.field(2, betterproto2.TYPE_BOOL)
@@ -1830,9 +1573,7 @@ class FieldOptions(betterproto2.Message):
1830
1573
  a more efficient representation on the wire. Rather than repeatedly
1831
1574
  writing the tag and type for each element, the entire array is encoded as
1832
1575
  a single length-delimited blob. In proto3, only explicit setting it to
1833
- false will avoid using packed encoding. This option is prohibited in
1834
- Editions, but the `repeated_field_encoding` feature can be used to control
1835
- the behavior.
1576
+ false will avoid using packed encoding.
1836
1577
  """
1837
1578
 
1838
1579
  jstype: "FieldOptionsJsType" = betterproto2.field(
@@ -1882,8 +1623,11 @@ class FieldOptions(betterproto2.Message):
1882
1623
  check its required fields, regardless of whether or not the message has
1883
1624
  been parsed.
1884
1625
 
1885
- As of May 2022, lazy verifies the contents of the byte stream during
1886
- parsing. An invalid byte stream will cause the overall parsing to fail.
1626
+ As of 2021, lazy does no correctness checks on the byte stream during
1627
+ parsing. This may lead to crashes if and when an invalid byte stream is
1628
+ finally parsed upon access.
1629
+
1630
+ TODO(b/211906113): Enable validation on lazy fields.
1887
1631
  """
1888
1632
 
1889
1633
  unverified_lazy: "bool" = betterproto2.field(15, betterproto2.TYPE_BOOL)
@@ -1906,28 +1650,7 @@ class FieldOptions(betterproto2.Message):
1906
1650
  For Google-internal migration only. Do not use.
1907
1651
  """
1908
1652
 
1909
- debug_redact: "bool" = betterproto2.field(16, betterproto2.TYPE_BOOL)
1910
- """
1911
- Indicate that the field value should not be printed out when using debug
1912
- formats, e.g. when the field contains sensitive credentials.
1913
- """
1914
-
1915
- retention: "FieldOptionsOptionRetention" = betterproto2.field(
1916
- 17, betterproto2.TYPE_ENUM, default_factory=lambda: FieldOptionsOptionRetention(0)
1917
- )
1918
-
1919
- targets: "List[FieldOptionsOptionTargetType]" = betterproto2.field(19, betterproto2.TYPE_ENUM, repeated=True)
1920
-
1921
- edition_defaults: "List[FieldOptionsEditionDefault]" = betterproto2.field(
1922
- 20, betterproto2.TYPE_MESSAGE, repeated=True
1923
- )
1924
-
1925
- features: "Optional[FeatureSet]" = betterproto2.field(21, betterproto2.TYPE_MESSAGE, optional=True)
1926
- """
1927
- Any features defined in the specific edition.
1928
- """
1929
-
1930
- uninterpreted_option: "List[UninterpretedOption]" = betterproto2.field(
1653
+ uninterpreted_option: "list[UninterpretedOption]" = betterproto2.field(
1931
1654
  999, betterproto2.TYPE_MESSAGE, repeated=True
1932
1655
  )
1933
1656
  """
@@ -1938,19 +1661,6 @@ class FieldOptions(betterproto2.Message):
1938
1661
  default_message_pool.register_message("google.protobuf", "FieldOptions", FieldOptions)
1939
1662
 
1940
1663
 
1941
- @dataclass(eq=False, repr=False)
1942
- class FieldOptionsEditionDefault(betterproto2.Message):
1943
- edition: "Edition" = betterproto2.field(3, betterproto2.TYPE_ENUM, default_factory=lambda: Edition(0))
1944
-
1945
- value: "str" = betterproto2.field(2, betterproto2.TYPE_STRING)
1946
- """
1947
- Textproto value.
1948
- """
1949
-
1950
-
1951
- default_message_pool.register_message("google.protobuf", "FieldOptions.EditionDefault", FieldOptionsEditionDefault)
1952
-
1953
-
1954
1664
  @dataclass(eq=False, repr=False)
1955
1665
  class FileDescriptorProto(betterproto2.Message):
1956
1666
  """
@@ -1967,36 +1677,36 @@ class FileDescriptorProto(betterproto2.Message):
1967
1677
  e.g. "foo", "foo.bar", etc.
1968
1678
  """
1969
1679
 
1970
- dependency: "List[str]" = betterproto2.field(3, betterproto2.TYPE_STRING, repeated=True)
1680
+ dependency: "list[str]" = betterproto2.field(3, betterproto2.TYPE_STRING, repeated=True)
1971
1681
  """
1972
1682
  Names of files imported by this file.
1973
1683
  """
1974
1684
 
1975
- public_dependency: "List[int]" = betterproto2.field(10, betterproto2.TYPE_INT32, repeated=True)
1685
+ public_dependency: "list[int]" = betterproto2.field(10, betterproto2.TYPE_INT32, repeated=True)
1976
1686
  """
1977
1687
  Indexes of the public imported files in the dependency list above.
1978
1688
  """
1979
1689
 
1980
- weak_dependency: "List[int]" = betterproto2.field(11, betterproto2.TYPE_INT32, repeated=True)
1690
+ weak_dependency: "list[int]" = betterproto2.field(11, betterproto2.TYPE_INT32, repeated=True)
1981
1691
  """
1982
1692
  Indexes of the weak imported files in the dependency list.
1983
1693
  For Google-internal migration only. Do not use.
1984
1694
  """
1985
1695
 
1986
- message_type: "List[DescriptorProto]" = betterproto2.field(4, betterproto2.TYPE_MESSAGE, repeated=True)
1696
+ message_type: "list[DescriptorProto]" = betterproto2.field(4, betterproto2.TYPE_MESSAGE, repeated=True)
1987
1697
  """
1988
1698
  All top-level definitions in this file.
1989
1699
  """
1990
1700
 
1991
- enum_type: "List[EnumDescriptorProto]" = betterproto2.field(5, betterproto2.TYPE_MESSAGE, repeated=True)
1701
+ enum_type: "list[EnumDescriptorProto]" = betterproto2.field(5, betterproto2.TYPE_MESSAGE, repeated=True)
1992
1702
 
1993
- service: "List[ServiceDescriptorProto]" = betterproto2.field(6, betterproto2.TYPE_MESSAGE, repeated=True)
1703
+ service: "list[ServiceDescriptorProto]" = betterproto2.field(6, betterproto2.TYPE_MESSAGE, repeated=True)
1994
1704
 
1995
- extension: "List[FieldDescriptorProto]" = betterproto2.field(7, betterproto2.TYPE_MESSAGE, repeated=True)
1705
+ extension: "list[FieldDescriptorProto]" = betterproto2.field(7, betterproto2.TYPE_MESSAGE, repeated=True)
1996
1706
 
1997
- options: "Optional[FileOptions]" = betterproto2.field(8, betterproto2.TYPE_MESSAGE, optional=True)
1707
+ options: "FileOptions | None" = betterproto2.field(8, betterproto2.TYPE_MESSAGE, optional=True)
1998
1708
 
1999
- source_code_info: "Optional[SourceCodeInfo]" = betterproto2.field(9, betterproto2.TYPE_MESSAGE, optional=True)
1709
+ source_code_info: "SourceCodeInfo | None" = betterproto2.field(9, betterproto2.TYPE_MESSAGE, optional=True)
2000
1710
  """
2001
1711
  This field contains optional information about the original source code.
2002
1712
  You may safely remove this entire field without harming runtime
@@ -2007,14 +1717,7 @@ class FileDescriptorProto(betterproto2.Message):
2007
1717
  syntax: "str" = betterproto2.field(12, betterproto2.TYPE_STRING)
2008
1718
  """
2009
1719
  The syntax of the proto file.
2010
- The supported values are "proto2", "proto3", and "editions".
2011
-
2012
- If `edition` is present, this value must be "editions".
2013
- """
2014
-
2015
- edition: "Edition" = betterproto2.field(14, betterproto2.TYPE_ENUM, default_factory=lambda: Edition(0))
2016
- """
2017
- The edition of the proto file.
1720
+ The supported values are "proto2" and "proto3".
2018
1721
  """
2019
1722
 
2020
1723
 
@@ -2028,7 +1731,7 @@ class FileDescriptorSet(betterproto2.Message):
2028
1731
  files it parses.
2029
1732
  """
2030
1733
 
2031
- file: "List[FileDescriptorProto]" = betterproto2.field(1, betterproto2.TYPE_MESSAGE, repeated=True)
1734
+ file: "list[FileDescriptorProto]" = betterproto2.field(1, betterproto2.TYPE_MESSAGE, repeated=True)
2032
1735
 
2033
1736
 
2034
1737
  default_message_pool.register_message("google.protobuf", "FileDescriptorSet", FileDescriptorSet)
@@ -2205,12 +1908,7 @@ class FileOptions(betterproto2.Message):
2205
1908
  determining the ruby package.
2206
1909
  """
2207
1910
 
2208
- features: "Optional[FeatureSet]" = betterproto2.field(50, betterproto2.TYPE_MESSAGE, optional=True)
2209
- """
2210
- Any features defined in the specific edition.
2211
- """
2212
-
2213
- uninterpreted_option: "List[UninterpretedOption]" = betterproto2.field(
1911
+ uninterpreted_option: "list[UninterpretedOption]" = betterproto2.field(
2214
1912
  999, betterproto2.TYPE_MESSAGE, repeated=True
2215
1913
  )
2216
1914
  """
@@ -2240,6 +1938,28 @@ class FloatValue(betterproto2.Message):
2240
1938
  The float value.
2241
1939
  """
2242
1940
 
1941
+ @classmethod
1942
+ def from_dict(cls, value):
1943
+ if isinstance(value, float):
1944
+ return FloatValue(value=value)
1945
+ return super().from_dict(value)
1946
+
1947
+ def to_dict(
1948
+ self,
1949
+ *,
1950
+ output_format: betterproto2.OutputFormat = betterproto2.OutputFormat.PROTO_JSON,
1951
+ casing: betterproto2.Casing = betterproto2.Casing.CAMEL,
1952
+ include_default_values: bool = False,
1953
+ ) -> dict[str, typing.Any] | typing.Any:
1954
+ return self.value
1955
+
1956
+ @staticmethod
1957
+ def from_wrapped(wrapped: float) -> "FloatValue":
1958
+ return FloatValue(value=wrapped)
1959
+
1960
+ def to_wrapped(self) -> float:
1961
+ return self.value
1962
+
2243
1963
 
2244
1964
  default_message_pool.register_message("google.protobuf", "FloatValue", FloatValue)
2245
1965
 
@@ -2252,7 +1972,7 @@ class GeneratedCodeInfo(betterproto2.Message):
2252
1972
  source file, but may contain references to different source .proto files.
2253
1973
  """
2254
1974
 
2255
- annotation: "List[GeneratedCodeInfoAnnotation]" = betterproto2.field(1, betterproto2.TYPE_MESSAGE, repeated=True)
1975
+ annotation: "list[GeneratedCodeInfoAnnotation]" = betterproto2.field(1, betterproto2.TYPE_MESSAGE, repeated=True)
2256
1976
  """
2257
1977
  An Annotation connects some span of text in generated code to an element
2258
1978
  of its generating .proto file.
@@ -2264,7 +1984,7 @@ default_message_pool.register_message("google.protobuf", "GeneratedCodeInfo", Ge
2264
1984
 
2265
1985
  @dataclass(eq=False, repr=False)
2266
1986
  class GeneratedCodeInfoAnnotation(betterproto2.Message):
2267
- path: "List[int]" = betterproto2.field(1, betterproto2.TYPE_INT32, repeated=True)
1987
+ path: "list[int]" = betterproto2.field(1, betterproto2.TYPE_INT32, repeated=True)
2268
1988
  """
2269
1989
  Identifies the element in the original source .proto file. This field
2270
1990
  is formatted the same as SourceCodeInfo.Location.path.
@@ -2284,14 +2004,10 @@ class GeneratedCodeInfoAnnotation(betterproto2.Message):
2284
2004
  end: "int" = betterproto2.field(4, betterproto2.TYPE_INT32)
2285
2005
  """
2286
2006
  Identifies the ending offset in bytes in the generated code that
2287
- relates to the identified object. The end offset should be one past
2007
+ relates to the identified offset. The end offset should be one past
2288
2008
  the last relevant byte (so the length of the text = end - begin).
2289
2009
  """
2290
2010
 
2291
- semantic: "GeneratedCodeInfoAnnotationSemantic" = betterproto2.field(
2292
- 5, betterproto2.TYPE_ENUM, default_factory=lambda: GeneratedCodeInfoAnnotationSemantic(0)
2293
- )
2294
-
2295
2011
 
2296
2012
  default_message_pool.register_message("google.protobuf", "GeneratedCodeInfo.Annotation", GeneratedCodeInfoAnnotation)
2297
2013
 
@@ -2309,6 +2025,28 @@ class Int32Value(betterproto2.Message):
2309
2025
  The int32 value.
2310
2026
  """
2311
2027
 
2028
+ @classmethod
2029
+ def from_dict(cls, value):
2030
+ if isinstance(value, int):
2031
+ return Int32Value(value=value)
2032
+ return super().from_dict(value)
2033
+
2034
+ def to_dict(
2035
+ self,
2036
+ *,
2037
+ output_format: betterproto2.OutputFormat = betterproto2.OutputFormat.PROTO_JSON,
2038
+ casing: betterproto2.Casing = betterproto2.Casing.CAMEL,
2039
+ include_default_values: bool = False,
2040
+ ) -> dict[str, typing.Any] | typing.Any:
2041
+ return self.value
2042
+
2043
+ @staticmethod
2044
+ def from_wrapped(wrapped: int) -> "Int32Value":
2045
+ return Int32Value(value=wrapped)
2046
+
2047
+ def to_wrapped(self) -> int:
2048
+ return self.value
2049
+
2312
2050
 
2313
2051
  default_message_pool.register_message("google.protobuf", "Int32Value", Int32Value)
2314
2052
 
@@ -2326,6 +2064,28 @@ class Int64Value(betterproto2.Message):
2326
2064
  The int64 value.
2327
2065
  """
2328
2066
 
2067
+ @classmethod
2068
+ def from_dict(cls, value):
2069
+ if isinstance(value, int):
2070
+ return Int64Value(value=value)
2071
+ return super().from_dict(value)
2072
+
2073
+ def to_dict(
2074
+ self,
2075
+ *,
2076
+ output_format: betterproto2.OutputFormat = betterproto2.OutputFormat.PROTO_JSON,
2077
+ casing: betterproto2.Casing = betterproto2.Casing.CAMEL,
2078
+ include_default_values: bool = False,
2079
+ ) -> dict[str, typing.Any] | typing.Any:
2080
+ return self.value
2081
+
2082
+ @staticmethod
2083
+ def from_wrapped(wrapped: int) -> "Int64Value":
2084
+ return Int64Value(value=wrapped)
2085
+
2086
+ def to_wrapped(self) -> int:
2087
+ return self.value
2088
+
2329
2089
 
2330
2090
  default_message_pool.register_message("google.protobuf", "Int64Value", Int64Value)
2331
2091
 
@@ -2338,7 +2098,7 @@ class ListValue(betterproto2.Message):
2338
2098
  The JSON representation for `ListValue` is JSON array.
2339
2099
  """
2340
2100
 
2341
- values: "List[Value]" = betterproto2.field(1, betterproto2.TYPE_MESSAGE, repeated=True)
2101
+ values: "list[Value]" = betterproto2.field(1, betterproto2.TYPE_MESSAGE, repeated=True)
2342
2102
  """
2343
2103
  Repeated field of dynamically typed values.
2344
2104
  """
@@ -2388,10 +2148,6 @@ class MessageOptions(betterproto2.Message):
2388
2148
 
2389
2149
  map_entry: "bool" = betterproto2.field(7, betterproto2.TYPE_BOOL)
2390
2150
  """
2391
- NOTE: Do not set the option in .proto files. Always use the maps syntax
2392
- instead. The option should only be implicitly set by the proto compiler
2393
- parser.
2394
-
2395
2151
  Whether the message is an automatically generated map entry type for the
2396
2152
  maps field.
2397
2153
 
@@ -2409,39 +2165,19 @@ class MessageOptions(betterproto2.Message):
2409
2165
  use a native map in the target language to hold the keys and values.
2410
2166
  The reflection APIs in such implementations still need to work as
2411
2167
  if the field is a repeated message field.
2412
- """
2413
-
2414
- deprecated_legacy_json_field_conflicts: "bool" = betterproto2.field(11, betterproto2.TYPE_BOOL)
2415
- """
2416
- Enable the legacy handling of JSON field name conflicts. This lowercases
2417
- and strips underscored from the fields before comparison in proto3 only.
2418
- The new behavior takes `json_name` into account and applies to proto2 as
2419
- well.
2420
-
2421
- This should only be used as a temporary measure against broken builds due
2422
- to the change in behavior for JSON field name conflicts.
2423
2168
 
2424
- TODO This is legacy behavior we plan to remove once downstream
2425
- teams have had time to migrate.
2426
- """
2427
-
2428
- features: "Optional[FeatureSet]" = betterproto2.field(12, betterproto2.TYPE_MESSAGE, optional=True)
2429
- """
2430
- Any features defined in the specific edition.
2169
+ NOTE: Do not set the option in .proto files. Always use the maps syntax
2170
+ instead. The option should only be implicitly set by the proto compiler
2171
+ parser.
2431
2172
  """
2432
2173
 
2433
- uninterpreted_option: "List[UninterpretedOption]" = betterproto2.field(
2174
+ uninterpreted_option: "list[UninterpretedOption]" = betterproto2.field(
2434
2175
  999, betterproto2.TYPE_MESSAGE, repeated=True
2435
2176
  )
2436
2177
  """
2437
2178
  The parser stores options it doesn't recognize here. See above.
2438
2179
  """
2439
2180
 
2440
- def __post_init__(self) -> None:
2441
- super().__post_init__()
2442
- if self.is_set("deprecated_legacy_json_field_conflicts"):
2443
- warnings.warn("MessageOptions.deprecated_legacy_json_field_conflicts is deprecated", DeprecationWarning)
2444
-
2445
2181
 
2446
2182
  default_message_pool.register_message("google.protobuf", "MessageOptions", MessageOptions)
2447
2183
 
@@ -2477,7 +2213,7 @@ class Method(betterproto2.Message):
2477
2213
  If true, the response is streamed.
2478
2214
  """
2479
2215
 
2480
- options: "List[Option]" = betterproto2.field(6, betterproto2.TYPE_MESSAGE, repeated=True)
2216
+ options: "list[Option]" = betterproto2.field(6, betterproto2.TYPE_MESSAGE, repeated=True)
2481
2217
  """
2482
2218
  Any metadata attached to the method.
2483
2219
  """
@@ -2507,7 +2243,7 @@ class MethodDescriptorProto(betterproto2.Message):
2507
2243
 
2508
2244
  output_type: "str" = betterproto2.field(3, betterproto2.TYPE_STRING)
2509
2245
 
2510
- options: "Optional[MethodOptions]" = betterproto2.field(4, betterproto2.TYPE_MESSAGE, optional=True)
2246
+ options: "MethodOptions | None" = betterproto2.field(4, betterproto2.TYPE_MESSAGE, optional=True)
2511
2247
 
2512
2248
  client_streaming: "bool" = betterproto2.field(5, betterproto2.TYPE_BOOL)
2513
2249
  """
@@ -2542,12 +2278,7 @@ class MethodOptions(betterproto2.Message):
2542
2278
  34, betterproto2.TYPE_ENUM, default_factory=lambda: MethodOptionsIdempotencyLevel(0)
2543
2279
  )
2544
2280
 
2545
- features: "Optional[FeatureSet]" = betterproto2.field(35, betterproto2.TYPE_MESSAGE, optional=True)
2546
- """
2547
- Any features defined in the specific edition.
2548
- """
2549
-
2550
- uninterpreted_option: "List[UninterpretedOption]" = betterproto2.field(
2281
+ uninterpreted_option: "list[UninterpretedOption]" = betterproto2.field(
2551
2282
  999, betterproto2.TYPE_MESSAGE, repeated=True
2552
2283
  )
2553
2284
  """
@@ -2608,7 +2339,7 @@ class Mixin(betterproto2.Message):
2608
2339
  The mixin construct implies that all methods in `AccessControl` are
2609
2340
  also declared with same name and request/response types in
2610
2341
  `Storage`. A documentation generator or annotation processor will
2611
- see the effective `Storage.GetAcl` method after inherting
2342
+ see the effective `Storage.GetAcl` method after inheriting
2612
2343
  documentation and annotations as follows:
2613
2344
 
2614
2345
  service Storage {
@@ -2664,7 +2395,7 @@ class OneofDescriptorProto(betterproto2.Message):
2664
2395
 
2665
2396
  name: "str" = betterproto2.field(1, betterproto2.TYPE_STRING)
2666
2397
 
2667
- options: "Optional[OneofOptions]" = betterproto2.field(2, betterproto2.TYPE_MESSAGE, optional=True)
2398
+ options: "OneofOptions | None" = betterproto2.field(2, betterproto2.TYPE_MESSAGE, optional=True)
2668
2399
 
2669
2400
 
2670
2401
  default_message_pool.register_message("google.protobuf", "OneofDescriptorProto", OneofDescriptorProto)
@@ -2672,12 +2403,7 @@ default_message_pool.register_message("google.protobuf", "OneofDescriptorProto",
2672
2403
 
2673
2404
  @dataclass(eq=False, repr=False)
2674
2405
  class OneofOptions(betterproto2.Message):
2675
- features: "Optional[FeatureSet]" = betterproto2.field(1, betterproto2.TYPE_MESSAGE, optional=True)
2676
- """
2677
- Any features defined in the specific edition.
2678
- """
2679
-
2680
- uninterpreted_option: "List[UninterpretedOption]" = betterproto2.field(
2406
+ uninterpreted_option: "list[UninterpretedOption]" = betterproto2.field(
2681
2407
  999, betterproto2.TYPE_MESSAGE, repeated=True
2682
2408
  )
2683
2409
  """
@@ -2703,7 +2429,7 @@ class Option(betterproto2.Message):
2703
2429
  `"google.api.http"`.
2704
2430
  """
2705
2431
 
2706
- value: "Optional[Any]" = betterproto2.field(2, betterproto2.TYPE_MESSAGE, optional=True)
2432
+ value: "Any | None" = betterproto2.field(2, betterproto2.TYPE_MESSAGE, optional=True)
2707
2433
  """
2708
2434
  The option's value packed in an Any message. If the value is a primitive,
2709
2435
  the corresponding wrapper type defined in google/protobuf/wrappers.proto
@@ -2723,9 +2449,9 @@ class ServiceDescriptorProto(betterproto2.Message):
2723
2449
 
2724
2450
  name: "str" = betterproto2.field(1, betterproto2.TYPE_STRING)
2725
2451
 
2726
- method: "List[MethodDescriptorProto]" = betterproto2.field(2, betterproto2.TYPE_MESSAGE, repeated=True)
2452
+ method: "list[MethodDescriptorProto]" = betterproto2.field(2, betterproto2.TYPE_MESSAGE, repeated=True)
2727
2453
 
2728
- options: "Optional[ServiceOptions]" = betterproto2.field(3, betterproto2.TYPE_MESSAGE, optional=True)
2454
+ options: "ServiceOptions | None" = betterproto2.field(3, betterproto2.TYPE_MESSAGE, optional=True)
2729
2455
 
2730
2456
 
2731
2457
  default_message_pool.register_message("google.protobuf", "ServiceDescriptorProto", ServiceDescriptorProto)
@@ -2733,11 +2459,6 @@ default_message_pool.register_message("google.protobuf", "ServiceDescriptorProto
2733
2459
 
2734
2460
  @dataclass(eq=False, repr=False)
2735
2461
  class ServiceOptions(betterproto2.Message):
2736
- features: "Optional[FeatureSet]" = betterproto2.field(34, betterproto2.TYPE_MESSAGE, optional=True)
2737
- """
2738
- Any features defined in the specific edition.
2739
- """
2740
-
2741
2462
  deprecated: "bool" = betterproto2.field(33, betterproto2.TYPE_BOOL)
2742
2463
  """
2743
2464
  Note: Field numbers 1 through 32 are reserved for Google's internal RPC
@@ -2751,7 +2472,7 @@ class ServiceOptions(betterproto2.Message):
2751
2472
  this is a formalization for deprecating services.
2752
2473
  """
2753
2474
 
2754
- uninterpreted_option: "List[UninterpretedOption]" = betterproto2.field(
2475
+ uninterpreted_option: "list[UninterpretedOption]" = betterproto2.field(
2755
2476
  999, betterproto2.TYPE_MESSAGE, repeated=True
2756
2477
  )
2757
2478
  """
@@ -2772,7 +2493,7 @@ class SourceCodeInfo(betterproto2.Message):
2772
2493
  FileDescriptorProto was generated.
2773
2494
  """
2774
2495
 
2775
- location: "List[SourceCodeInfoLocation]" = betterproto2.field(1, betterproto2.TYPE_MESSAGE, repeated=True)
2496
+ location: "list[SourceCodeInfoLocation]" = betterproto2.field(1, betterproto2.TYPE_MESSAGE, repeated=True)
2776
2497
  """
2777
2498
  A Location identifies a piece of source code in a .proto file which
2778
2499
  corresponds to a particular definition. This information is intended
@@ -2825,7 +2546,7 @@ default_message_pool.register_message("google.protobuf", "SourceCodeInfo", Sourc
2825
2546
 
2826
2547
  @dataclass(eq=False, repr=False)
2827
2548
  class SourceCodeInfoLocation(betterproto2.Message):
2828
- path: "List[int]" = betterproto2.field(1, betterproto2.TYPE_INT32, repeated=True)
2549
+ path: "list[int]" = betterproto2.field(1, betterproto2.TYPE_INT32, repeated=True)
2829
2550
  """
2830
2551
  Identifies which part of the FileDescriptorProto was defined at this
2831
2552
  location.
@@ -2852,7 +2573,7 @@ class SourceCodeInfoLocation(betterproto2.Message):
2852
2573
  of the label to the terminating semicolon).
2853
2574
  """
2854
2575
 
2855
- span: "List[int]" = betterproto2.field(2, betterproto2.TYPE_INT32, repeated=True)
2576
+ span: "list[int]" = betterproto2.field(2, betterproto2.TYPE_INT32, repeated=True)
2856
2577
  """
2857
2578
  Always has exactly three or four elements: start line, start column,
2858
2579
  end line (optional, otherwise assumed same as start line), end column.
@@ -2914,7 +2635,7 @@ class SourceCodeInfoLocation(betterproto2.Message):
2914
2635
 
2915
2636
  trailing_comments: "str" = betterproto2.field(4, betterproto2.TYPE_STRING)
2916
2637
 
2917
- leading_detached_comments: "List[str]" = betterproto2.field(6, betterproto2.TYPE_STRING, repeated=True)
2638
+ leading_detached_comments: "list[str]" = betterproto2.field(6, betterproto2.TYPE_STRING, repeated=True)
2918
2639
 
2919
2640
 
2920
2641
  default_message_pool.register_message("google.protobuf", "SourceCodeInfo.Location", SourceCodeInfoLocation)
@@ -2950,6 +2671,28 @@ class StringValue(betterproto2.Message):
2950
2671
  The string value.
2951
2672
  """
2952
2673
 
2674
+ @classmethod
2675
+ def from_dict(cls, value):
2676
+ if isinstance(value, str):
2677
+ return StringValue(value=value)
2678
+ return super().from_dict(value)
2679
+
2680
+ def to_dict(
2681
+ self,
2682
+ *,
2683
+ output_format: betterproto2.OutputFormat = betterproto2.OutputFormat.PROTO_JSON,
2684
+ casing: betterproto2.Casing = betterproto2.Casing.CAMEL,
2685
+ include_default_values: bool = False,
2686
+ ) -> dict[str, typing.Any] | typing.Any:
2687
+ return self.value
2688
+
2689
+ @staticmethod
2690
+ def from_wrapped(wrapped: str) -> "StringValue":
2691
+ return StringValue(value=wrapped)
2692
+
2693
+ def to_wrapped(self) -> str:
2694
+ return self.value
2695
+
2953
2696
 
2954
2697
  default_message_pool.register_message("google.protobuf", "StringValue", StringValue)
2955
2698
 
@@ -2967,8 +2710,8 @@ class Struct(betterproto2.Message):
2967
2710
  The JSON representation for `Struct` is JSON object.
2968
2711
  """
2969
2712
 
2970
- fields: "Dict[str, Value]" = betterproto2.field(
2971
- 1, betterproto2.TYPE_MAP, map_types=(betterproto2.TYPE_STRING, betterproto2.TYPE_MESSAGE)
2713
+ fields: "dict[str, Value]" = betterproto2.field(
2714
+ 1, betterproto2.TYPE_MAP, map_meta=betterproto2.map_meta(betterproto2.TYPE_STRING, betterproto2.TYPE_MESSAGE)
2972
2715
  )
2973
2716
  """
2974
2717
  Unordered map of dynamically typed values.
@@ -3068,7 +2811,7 @@ class Timestamp(betterproto2.Message):
3068
2811
  [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with
3069
2812
  the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use
3070
2813
  the Joda Time's [`ISODateTimeFormat.dateTime()`](
3071
- http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime()
2814
+ http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D
3072
2815
  ) to obtain a formatter capable of generating timestamps in this format.
3073
2816
  """
3074
2817
 
@@ -3089,6 +2832,11 @@ class Timestamp(betterproto2.Message):
3089
2832
 
3090
2833
  @classmethod
3091
2834
  def from_datetime(cls, dt: datetime.datetime) -> "Timestamp":
2835
+ if not dt.tzinfo:
2836
+ raise ValueError("datetime must be timezone aware")
2837
+
2838
+ dt = dt.astimezone(datetime.timezone.utc)
2839
+
3092
2840
  # manual epoch offset calulation to avoid rounding errors,
3093
2841
  # to support negative timestamps (before 1970) and skirt
3094
2842
  # around datetime bugs (apparently 0 isn't a year in [0, 9999]??)
@@ -3120,13 +2868,41 @@ class Timestamp(betterproto2.Message):
3120
2868
  return f"{result}Z"
3121
2869
  if (nanos % 1e6) == 0:
3122
2870
  # Serialize 3 fractional digits.
3123
- return f"{result}.{int(nanos // 1e6) :03d}Z"
2871
+ return f"{result}.{int(nanos // 1e6):03d}Z"
3124
2872
  if (nanos % 1e3) == 0:
3125
2873
  # Serialize 6 fractional digits.
3126
- return f"{result}.{int(nanos // 1e3) :06d}Z"
2874
+ return f"{result}.{int(nanos // 1e3):06d}Z"
3127
2875
  # Serialize 9 fractional digits.
3128
2876
  return f"{result}.{nanos:09d}"
3129
2877
 
2878
+ @classmethod
2879
+ def from_dict(cls, value):
2880
+ if isinstance(value, str):
2881
+ dt = dateutil.parser.isoparse(value)
2882
+ dt = dt.astimezone(datetime.timezone.utc)
2883
+ return Timestamp.from_datetime(dt)
2884
+
2885
+ return super().from_dict(value)
2886
+
2887
+ def to_dict(
2888
+ self,
2889
+ *,
2890
+ output_format: betterproto2.OutputFormat = betterproto2.OutputFormat.PROTO_JSON,
2891
+ casing: betterproto2.Casing = betterproto2.Casing.CAMEL,
2892
+ include_default_values: bool = False,
2893
+ ) -> dict[str, typing.Any] | typing.Any:
2894
+ # If the output format is PYTHON, we should have kept the wraped type without building the real class
2895
+ assert output_format == betterproto2.OutputFormat.PROTO_JSON
2896
+
2897
+ return Timestamp.timestamp_to_json(self.to_datetime())
2898
+
2899
+ @staticmethod
2900
+ def from_wrapped(wrapped: datetime.datetime) -> "Timestamp":
2901
+ return Timestamp.from_datetime(wrapped)
2902
+
2903
+ def to_wrapped(self) -> datetime.datetime:
2904
+ return self.to_datetime()
2905
+
3130
2906
 
3131
2907
  default_message_pool.register_message("google.protobuf", "Timestamp", Timestamp)
3132
2908
 
@@ -3142,22 +2918,22 @@ class Type(betterproto2.Message):
3142
2918
  The fully qualified message name.
3143
2919
  """
3144
2920
 
3145
- fields: "List[Field]" = betterproto2.field(2, betterproto2.TYPE_MESSAGE, repeated=True)
2921
+ fields: "list[Field]" = betterproto2.field(2, betterproto2.TYPE_MESSAGE, repeated=True)
3146
2922
  """
3147
2923
  The list of fields.
3148
2924
  """
3149
2925
 
3150
- oneofs: "List[str]" = betterproto2.field(3, betterproto2.TYPE_STRING, repeated=True)
2926
+ oneofs: "list[str]" = betterproto2.field(3, betterproto2.TYPE_STRING, repeated=True)
3151
2927
  """
3152
2928
  The list of types appearing in `oneof` definitions in this type.
3153
2929
  """
3154
2930
 
3155
- options: "List[Option]" = betterproto2.field(4, betterproto2.TYPE_MESSAGE, repeated=True)
2931
+ options: "list[Option]" = betterproto2.field(4, betterproto2.TYPE_MESSAGE, repeated=True)
3156
2932
  """
3157
2933
  The protocol buffer options.
3158
2934
  """
3159
2935
 
3160
- source_context: "Optional[SourceContext]" = betterproto2.field(5, betterproto2.TYPE_MESSAGE, optional=True)
2936
+ source_context: "SourceContext | None" = betterproto2.field(5, betterproto2.TYPE_MESSAGE, optional=True)
3161
2937
  """
3162
2938
  The source context.
3163
2939
  """
@@ -3167,11 +2943,6 @@ class Type(betterproto2.Message):
3167
2943
  The source syntax.
3168
2944
  """
3169
2945
 
3170
- edition: "str" = betterproto2.field(7, betterproto2.TYPE_STRING)
3171
- """
3172
- The source edition string, only valid when syntax is SYNTAX_EDITIONS.
3173
- """
3174
-
3175
2946
 
3176
2947
  default_message_pool.register_message("google.protobuf", "Type", Type)
3177
2948
 
@@ -3189,6 +2960,28 @@ class UInt32Value(betterproto2.Message):
3189
2960
  The uint32 value.
3190
2961
  """
3191
2962
 
2963
+ @classmethod
2964
+ def from_dict(cls, value):
2965
+ if isinstance(value, int):
2966
+ return UInt32Value(value=value)
2967
+ return super().from_dict(value)
2968
+
2969
+ def to_dict(
2970
+ self,
2971
+ *,
2972
+ output_format: betterproto2.OutputFormat = betterproto2.OutputFormat.PROTO_JSON,
2973
+ casing: betterproto2.Casing = betterproto2.Casing.CAMEL,
2974
+ include_default_values: bool = False,
2975
+ ) -> dict[str, typing.Any] | typing.Any:
2976
+ return self.value
2977
+
2978
+ @staticmethod
2979
+ def from_wrapped(wrapped: int) -> "UInt32Value":
2980
+ return UInt32Value(value=wrapped)
2981
+
2982
+ def to_wrapped(self) -> int:
2983
+ return self.value
2984
+
3192
2985
 
3193
2986
  default_message_pool.register_message("google.protobuf", "UInt32Value", UInt32Value)
3194
2987
 
@@ -3206,6 +2999,28 @@ class UInt64Value(betterproto2.Message):
3206
2999
  The uint64 value.
3207
3000
  """
3208
3001
 
3002
+ @classmethod
3003
+ def from_dict(cls, value):
3004
+ if isinstance(value, int):
3005
+ return UInt64Value(value=value)
3006
+ return super().from_dict(value)
3007
+
3008
+ def to_dict(
3009
+ self,
3010
+ *,
3011
+ output_format: betterproto2.OutputFormat = betterproto2.OutputFormat.PROTO_JSON,
3012
+ casing: betterproto2.Casing = betterproto2.Casing.CAMEL,
3013
+ include_default_values: bool = False,
3014
+ ) -> dict[str, typing.Any] | typing.Any:
3015
+ return self.value
3016
+
3017
+ @staticmethod
3018
+ def from_wrapped(wrapped: int) -> "UInt64Value":
3019
+ return UInt64Value(value=wrapped)
3020
+
3021
+ def to_wrapped(self) -> int:
3022
+ return self.value
3023
+
3209
3024
 
3210
3025
  default_message_pool.register_message("google.protobuf", "UInt64Value", UInt64Value)
3211
3026
 
@@ -3221,7 +3036,7 @@ class UninterpretedOption(betterproto2.Message):
3221
3036
  in them.
3222
3037
  """
3223
3038
 
3224
- name: "List[UninterpretedOptionNamePart]" = betterproto2.field(2, betterproto2.TYPE_MESSAGE, repeated=True)
3039
+ name: "list[UninterpretedOptionNamePart]" = betterproto2.field(2, betterproto2.TYPE_MESSAGE, repeated=True)
3225
3040
 
3226
3041
  identifier_value: "str" = betterproto2.field(3, betterproto2.TYPE_STRING)
3227
3042
  """
@@ -3275,32 +3090,32 @@ class Value(betterproto2.Message):
3275
3090
  - kind: The kind of value.
3276
3091
  """
3277
3092
 
3278
- null_value: "Optional[NullValue]" = betterproto2.field(1, betterproto2.TYPE_ENUM, optional=True, group="kind")
3093
+ null_value: "NullValue | None" = betterproto2.field(1, betterproto2.TYPE_ENUM, optional=True, group="kind")
3279
3094
  """
3280
3095
  Represents a null value.
3281
3096
  """
3282
3097
 
3283
- number_value: "Optional[float]" = betterproto2.field(2, betterproto2.TYPE_DOUBLE, optional=True, group="kind")
3098
+ number_value: "float | None" = betterproto2.field(2, betterproto2.TYPE_DOUBLE, optional=True, group="kind")
3284
3099
  """
3285
3100
  Represents a double value.
3286
3101
  """
3287
3102
 
3288
- string_value: "Optional[str]" = betterproto2.field(3, betterproto2.TYPE_STRING, optional=True, group="kind")
3103
+ string_value: "str | None" = betterproto2.field(3, betterproto2.TYPE_STRING, optional=True, group="kind")
3289
3104
  """
3290
3105
  Represents a string value.
3291
3106
  """
3292
3107
 
3293
- bool_value: "Optional[bool]" = betterproto2.field(4, betterproto2.TYPE_BOOL, optional=True, group="kind")
3108
+ bool_value: "bool | None" = betterproto2.field(4, betterproto2.TYPE_BOOL, optional=True, group="kind")
3294
3109
  """
3295
3110
  Represents a boolean value.
3296
3111
  """
3297
3112
 
3298
- struct_value: "Optional[Struct]" = betterproto2.field(5, betterproto2.TYPE_MESSAGE, optional=True, group="kind")
3113
+ struct_value: "Struct | None" = betterproto2.field(5, betterproto2.TYPE_MESSAGE, optional=True, group="kind")
3299
3114
  """
3300
3115
  Represents a structured value.
3301
3116
  """
3302
3117
 
3303
- list_value: "Optional[ListValue]" = betterproto2.field(6, betterproto2.TYPE_MESSAGE, optional=True, group="kind")
3118
+ list_value: "ListValue | None" = betterproto2.field(6, betterproto2.TYPE_MESSAGE, optional=True, group="kind")
3304
3119
  """
3305
3120
  Represents a repeated `Value`.
3306
3121
  """