protobuf: drop kwargs from constructors

pull/25/head
matejcik 6 years ago committed by Pavol Rusnak
parent b502169bae
commit c6ac4f2200
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

@ -76,16 +76,17 @@ def process_message_imports(descriptor):
def create_init_method(fields):
yield " def __init__("
yield " self,"
for field in fields:
for field in fields[:-1]:
yield " %s: %s = None," % (field.name, field.py_type)
yield " **kwargs"
# last field must not have a traling comma
yield " %s: %s = None" % (fields[-1].name, fields[-1].py_type)
yield " ) -> None:"
for field in fields:
if field.repeated:
yield " self.{0} = {0} if {0} is not None else []".format(field.name)
else:
yield " self.{0} = {0}".format(field.name)
yield " super().__init__(**kwargs)"
def process_message(descriptor, protobuf_module, msg_id, is_upy):
@ -113,6 +114,9 @@ def process_message(descriptor, protobuf_module, msg_id, is_upy):
yield ""
yield "class %s(p.MessageType):" % descriptor.name
if msg_id is not None:
yield " MESSAGE_WIRE_TYPE = %d" % msg_id
if fields:
yield " FIELDS = {"
for field in fields:
@ -135,12 +139,11 @@ def process_message(descriptor, protobuf_module, msg_id, is_upy):
yield " %d: ('%s', %s, %s),%s" % (field.number, field.name, field.proto_type, flags, comment)
yield " }"
yield ""
yield from create_init_method(fields)
if msg_id is not None:
yield " MESSAGE_WIRE_TYPE = %d" % msg_id
yield ""
yield from create_init_method(fields)
if not fields and not msg_id:
yield " pass"
def process_enum(descriptor, is_upy):

Loading…
Cancel
Save