mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-26 09:28:13 +00:00
protobuf: only import list when needed
This commit is contained in:
parent
389f1418ed
commit
2c70ac3a2f
15
tools/pb2py
15
tools/pb2py
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user