Fix template bug resulting in empty __post_init__ methods

This commit is contained in:
Nat Noordanus 2020-10-19 18:22:33 +02:00 committed by Basileus
parent fc90653ab1
commit bb646fe26f
4 changed files with 5 additions and 169 deletions

View File

@ -172,9 +172,6 @@ class Timestamp(betterproto.Message):
# count forward in time. Must be from 0 to 999,999,999 inclusive.
nanos: int = betterproto.int32_field(2)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class FieldMask(betterproto.Message):
@ -259,9 +256,6 @@ class FieldMask(betterproto.Message):
# The set of field mask paths.
paths: List[str] = betterproto.string_field(1)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class SourceContext(betterproto.Message):
@ -274,9 +268,6 @@ class SourceContext(betterproto.Message):
# protobuf element. For example: `"google/protobuf/source_context.proto"`.
file_name: str = betterproto.string_field(1)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class Any(betterproto.Message):
@ -335,9 +326,6 @@ class Any(betterproto.Message):
# Must be a valid serialized protocol buffer of the above specified type.
value: bytes = betterproto.bytes_field(2)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class Type(betterproto.Message):
@ -356,9 +344,6 @@ class Type(betterproto.Message):
# The source syntax.
syntax: "Syntax" = betterproto.enum_field(6)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class Field(betterproto.Message):
@ -387,9 +372,6 @@ class Field(betterproto.Message):
# The string value of the default value of this field. Proto2 syntax only.
default_value: str = betterproto.string_field(11)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class Enum(betterproto.Message):
@ -408,9 +390,6 @@ class Enum(betterproto.Message):
# The source syntax.
syntax: "Syntax" = betterproto.enum_field(5)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class EnumValue(betterproto.Message):
@ -423,9 +402,6 @@ class EnumValue(betterproto.Message):
# Protocol buffer options.
options: List["Option"] = betterproto.message_field(3)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class Option(betterproto.Message):
@ -445,9 +421,6 @@ class Option(betterproto.Message):
# value using the google.protobuf.Int32Value type.
value: "Any" = betterproto.message_field(2)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class Api(betterproto.Message):
@ -491,9 +464,6 @@ class Api(betterproto.Message):
# The source syntax of the service.
syntax: "Syntax" = betterproto.enum_field(7)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class Method(betterproto.Message):
@ -514,9 +484,6 @@ class Method(betterproto.Message):
# The source syntax of this method.
syntax: "Syntax" = betterproto.enum_field(7)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class Mixin(betterproto.Message):
@ -562,9 +529,6 @@ class Mixin(betterproto.Message):
# If non-empty specifies a path under which inherited HTTP paths are rooted.
root: str = betterproto.string_field(2)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class Duration(betterproto.Message):
@ -610,9 +574,6 @@ class Duration(betterproto.Message):
# `seconds` field. Must be from -999,999,999 to +999,999,999 inclusive.
nanos: int = betterproto.int32_field(2)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class Struct(betterproto.Message):
@ -630,9 +591,6 @@ class Struct(betterproto.Message):
1, betterproto.TYPE_STRING, betterproto.TYPE_MESSAGE
)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class Value(betterproto.Message):
@ -657,9 +615,6 @@ class Value(betterproto.Message):
# Represents a repeated `Value`.
list_value: "ListValue" = betterproto.message_field(6, group="kind")
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class ListValue(betterproto.Message):
@ -671,9 +626,6 @@ class ListValue(betterproto.Message):
# Repeated field of dynamically typed values.
values: List["Value"] = betterproto.message_field(1)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class DoubleValue(betterproto.Message):
@ -685,9 +637,6 @@ class DoubleValue(betterproto.Message):
# The double value.
value: float = betterproto.double_field(1)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class FloatValue(betterproto.Message):
@ -699,9 +648,6 @@ class FloatValue(betterproto.Message):
# The float value.
value: float = betterproto.float_field(1)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class Int64Value(betterproto.Message):
@ -713,9 +659,6 @@ class Int64Value(betterproto.Message):
# The int64 value.
value: int = betterproto.int64_field(1)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class UInt64Value(betterproto.Message):
@ -727,9 +670,6 @@ class UInt64Value(betterproto.Message):
# The uint64 value.
value: int = betterproto.uint64_field(1)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class Int32Value(betterproto.Message):
@ -741,9 +681,6 @@ class Int32Value(betterproto.Message):
# The int32 value.
value: int = betterproto.int32_field(1)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class UInt32Value(betterproto.Message):
@ -755,9 +692,6 @@ class UInt32Value(betterproto.Message):
# The uint32 value.
value: int = betterproto.uint32_field(1)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class BoolValue(betterproto.Message):
@ -769,9 +703,6 @@ class BoolValue(betterproto.Message):
# The bool value.
value: bool = betterproto.bool_field(1)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class StringValue(betterproto.Message):
@ -783,9 +714,6 @@ class StringValue(betterproto.Message):
# The string value.
value: str = betterproto.string_field(1)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class BytesValue(betterproto.Message):
@ -797,9 +725,6 @@ class BytesValue(betterproto.Message):
# The bytes value.
value: bytes = betterproto.bytes_field(1)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class Empty(betterproto.Message):
@ -813,9 +738,6 @@ class Empty(betterproto.Message):
pass
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class FileDescriptorSet(betterproto.Message):
@ -826,9 +748,6 @@ class FileDescriptorSet(betterproto.Message):
file: List["FileDescriptorProto"] = betterproto.message_field(1)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class FileDescriptorProto(betterproto.Message):
@ -858,9 +777,6 @@ class FileDescriptorProto(betterproto.Message):
# "proto3".
syntax: str = betterproto.string_field(12)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class DescriptorProto(betterproto.Message):
@ -881,9 +797,6 @@ class DescriptorProto(betterproto.Message):
# A given name may only be reserved once.
reserved_name: List[str] = betterproto.string_field(10)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class DescriptorProtoExtensionRange(betterproto.Message):
@ -891,9 +804,6 @@ class DescriptorProtoExtensionRange(betterproto.Message):
end: int = betterproto.int32_field(2)
options: "ExtensionRangeOptions" = betterproto.message_field(3)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class DescriptorProtoReservedRange(betterproto.Message):
@ -906,18 +816,12 @@ class DescriptorProtoReservedRange(betterproto.Message):
start: int = betterproto.int32_field(1)
end: int = betterproto.int32_field(2)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class ExtensionRangeOptions(betterproto.Message):
# The parser stores options it doesn't recognize here. See above.
uninterpreted_option: List["UninterpretedOption"] = betterproto.message_field(999)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class FieldDescriptorProto(betterproto.Message):
@ -952,9 +856,6 @@ class FieldDescriptorProto(betterproto.Message):
json_name: str = betterproto.string_field(10)
options: "FieldOptions" = betterproto.message_field(8)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class OneofDescriptorProto(betterproto.Message):
@ -963,9 +864,6 @@ class OneofDescriptorProto(betterproto.Message):
name: str = betterproto.string_field(1)
options: "OneofOptions" = betterproto.message_field(2)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class EnumDescriptorProto(betterproto.Message):
@ -984,9 +882,6 @@ class EnumDescriptorProto(betterproto.Message):
# be reserved once.
reserved_name: List[str] = betterproto.string_field(5)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class EnumDescriptorProtoEnumReservedRange(betterproto.Message):
@ -1000,9 +895,6 @@ class EnumDescriptorProtoEnumReservedRange(betterproto.Message):
start: int = betterproto.int32_field(1)
end: int = betterproto.int32_field(2)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class EnumValueDescriptorProto(betterproto.Message):
@ -1012,9 +904,6 @@ class EnumValueDescriptorProto(betterproto.Message):
number: int = betterproto.int32_field(2)
options: "EnumValueOptions" = betterproto.message_field(3)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class ServiceDescriptorProto(betterproto.Message):
@ -1024,9 +913,6 @@ class ServiceDescriptorProto(betterproto.Message):
method: List["MethodDescriptorProto"] = betterproto.message_field(2)
options: "ServiceOptions" = betterproto.message_field(3)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class MethodDescriptorProto(betterproto.Message):
@ -1043,9 +929,6 @@ class MethodDescriptorProto(betterproto.Message):
# Identifies if server streams multiple server messages
server_streaming: bool = betterproto.bool_field(6)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class FileOptions(betterproto.Message):
@ -1174,9 +1057,6 @@ class MessageOptions(betterproto.Message):
# The parser stores options it doesn't recognize here. See above.
uninterpreted_option: List["UninterpretedOption"] = betterproto.message_field(999)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class FieldOptions(betterproto.Message):
@ -1234,18 +1114,12 @@ class FieldOptions(betterproto.Message):
# The parser stores options it doesn't recognize here. See above.
uninterpreted_option: List["UninterpretedOption"] = betterproto.message_field(999)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class OneofOptions(betterproto.Message):
# The parser stores options it doesn't recognize here. See above.
uninterpreted_option: List["UninterpretedOption"] = betterproto.message_field(999)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class EnumOptions(betterproto.Message):
@ -1259,9 +1133,6 @@ class EnumOptions(betterproto.Message):
# The parser stores options it doesn't recognize here. See above.
uninterpreted_option: List["UninterpretedOption"] = betterproto.message_field(999)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class EnumValueOptions(betterproto.Message):
@ -1273,9 +1144,6 @@ class EnumValueOptions(betterproto.Message):
# The parser stores options it doesn't recognize here. See above.
uninterpreted_option: List["UninterpretedOption"] = betterproto.message_field(999)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class ServiceOptions(betterproto.Message):
@ -1286,9 +1154,6 @@ class ServiceOptions(betterproto.Message):
# The parser stores options it doesn't recognize here. See above.
uninterpreted_option: List["UninterpretedOption"] = betterproto.message_field(999)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class MethodOptions(betterproto.Message):
@ -1300,9 +1165,6 @@ class MethodOptions(betterproto.Message):
# The parser stores options it doesn't recognize here. See above.
uninterpreted_option: List["UninterpretedOption"] = betterproto.message_field(999)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class UninterpretedOption(betterproto.Message):
@ -1325,9 +1187,6 @@ class UninterpretedOption(betterproto.Message):
string_value: bytes = betterproto.bytes_field(7)
aggregate_value: str = betterproto.string_field(8)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class UninterpretedOptionNamePart(betterproto.Message):
@ -1342,9 +1201,6 @@ class UninterpretedOptionNamePart(betterproto.Message):
name_part: str = betterproto.string_field(1)
is_extension: bool = betterproto.bool_field(2)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class SourceCodeInfo(betterproto.Message):
@ -1384,9 +1240,6 @@ class SourceCodeInfo(betterproto.Message):
# as more types of locations could be recorded in the future.
location: List["SourceCodeInfoLocation"] = betterproto.message_field(1)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class SourceCodeInfoLocation(betterproto.Message):
@ -1434,9 +1287,6 @@ class SourceCodeInfoLocation(betterproto.Message):
trailing_comments: str = betterproto.string_field(4)
leading_detached_comments: List[str] = betterproto.string_field(6)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class GeneratedCodeInfo(betterproto.Message):
@ -1450,9 +1300,6 @@ class GeneratedCodeInfo(betterproto.Message):
# its generating .proto file.
annotation: List["GeneratedCodeInfoAnnotation"] = betterproto.message_field(1)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class GeneratedCodeInfoAnnotation(betterproto.Message):
@ -1468,6 +1315,3 @@ class GeneratedCodeInfoAnnotation(betterproto.Message):
# the identified offset. The end offset should be one past the last relevant
# byte (so the length of the text = end - begin).
end: int = betterproto.int32_field(4)
def __post_init__(self) -> None:
super().__post_init__()

View File

@ -18,9 +18,6 @@ class Version(betterproto.Message):
# be empty for mainline stable releases.
suffix: str = betterproto.string_field(4)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class CodeGeneratorRequest(betterproto.Message):
@ -49,9 +46,6 @@ class CodeGeneratorRequest(betterproto.Message):
# The version number of protocol compiler.
compiler_version: "Version" = betterproto.message_field(3)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class CodeGeneratorResponse(betterproto.Message):
@ -67,9 +61,6 @@ class CodeGeneratorResponse(betterproto.Message):
error: str = betterproto.string_field(1)
file: List["CodeGeneratorResponseFile"] = betterproto.message_field(15)
def __post_init__(self) -> None:
super().__post_init__()
@dataclass(eq=False, repr=False)
class CodeGeneratorResponseFile(betterproto.Message):
@ -118,8 +109,5 @@ class CodeGeneratorResponseFile(betterproto.Message):
# The file contents.
content: str = betterproto.string_field(15)
def __post_init__(self) -> None:
super().__post_init__()
import betterproto.lib.google.protobuf as betterproto_lib_google_protobuf

View File

@ -312,6 +312,10 @@ class MessageCompiler(ProtoContentBase):
if f.deprecated:
yield f.py_name
@property
def has_deprecated_fields(self) -> bool:
return any(self.deprecated_fields)
def is_map(
proto_field_obj: FieldDescriptorProto, parent_message: DescriptorProto

View File

@ -54,7 +54,7 @@ class {{ message.py_name }}(betterproto.Message):
pass
{% endif %}
{% if message.deprecated or message.deprecated_fields %}
{% if message.deprecated or message.has_deprecated_fields %}
def __post_init__(self) -> None:
{% if message.deprecated %}
warnings.warn("{{ message.py_name }} is deprecated", DeprecationWarning)