1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 15:38:11 +00:00

protobuf: only import list when needed

This commit is contained in:
matejcik 2018-05-09 15:14:57 +02:00 committed by Pavol Rusnak
parent 389f1418ed
commit 2c70ac3a2f
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

View File

@ -100,14 +100,19 @@ def process_message(descriptor, protobuf_module, msg_id, is_upy):
if is_upy:
yield "import protobuf as p"
else:
yield "from .. import protobuf as p"
fields = list(parse_field(number, field)
for number, field
in descriptor.fields_by_number.items())
if any(field.repeated for field in fields):
yield "if __debug__:"
yield " try:"
yield " from typing import List"
yield " except ImportError:"
yield " List = None"
else:
yield "from .. import protobuf as p"
yield "from typing import List"
yield from process_message_imports(descriptor)
@ -115,10 +120,6 @@ def process_message(descriptor, protobuf_module, msg_id, is_upy):
yield ""
yield "class %s(p.MessageType):" % descriptor.name
fields = list(parse_field(number, field)
for number, field
in descriptor.fields_by_number.items())
if fields:
yield " FIELDS = {"
for field in fields: