1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-03 12:00:59 +00:00

protobuf: drop Optional markers (relying on implicit optional)

and add a conditional import for List
This commit is contained in:
matejcik 2018-05-09 15:00:19 +02:00 committed by Pavol Rusnak
parent efa0f60493
commit 389f1418ed
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

View File

@ -84,7 +84,7 @@ def create_init_method(fields):
yield " def __init__(" yield " def __init__("
yield " self," yield " self,"
for field in fields: for field in fields:
yield " %s: Optional[%s] = None," % (field.name, field.py_type) yield " %s: %s = None," % (field.name, field.py_type)
yield " **kwargs" yield " **kwargs"
yield " ) -> None:" yield " ) -> None:"
for field in fields: for field in fields:
@ -100,9 +100,14 @@ def process_message(descriptor, protobuf_module, msg_id, is_upy):
if is_upy: if is_upy:
yield "import protobuf as p" yield "import protobuf as p"
yield "if __debug__:"
yield " try:"
yield " from typing import List"
yield " except ImportError:"
yield " List = None"
else: else:
yield "from .. import protobuf as p" yield "from .. import protobuf as p"
yield "from typing import List, Optional" yield "from typing import List"
yield from process_message_imports(descriptor) yield from process_message_imports(descriptor)