1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-24 15:28:10 +00:00

common/protob: fix wrong typing info for Lists

This commit is contained in:
Pavol Rusnak 2019-08-19 13:57:20 +02:00
parent f43652f2ea
commit 101ec1d161
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

View File

@ -51,6 +51,7 @@ class ProtoField:
type_name = attr.ib() type_name = attr.ib()
proto_type = attr.ib() proto_type = attr.ib()
py_type = attr.ib() py_type = attr.ib()
py_inner_type = attr.ib()
@classmethod @classmethod
def from_field(cls, descriptor, field): def from_field(cls, descriptor, field):
@ -73,6 +74,7 @@ class ProtoField:
"Unknown field type {} for field {}".format(field.type, field.name) "Unknown field type {} for field {}".format(field.type, field.name)
) from None ) from None
py_inner_type = py_type
if repeated: if repeated:
py_type = "List[{}]".format(py_type) py_type = "List[{}]".format(py_type)
@ -85,6 +87,7 @@ class ProtoField:
type_name=type_name, type_name=type_name,
proto_type=proto_type, proto_type=proto_type,
py_type=py_type, py_type=py_type,
py_inner_type=py_inner_type,
) )
@ -282,12 +285,12 @@ class Descriptor:
for field in all_enums: for field in all_enums:
allowed_values = self.enum_types[field.type_name] allowed_values = self.enum_types[field.type_name]
valuestr = ", ".join(str(v) for v in sorted(allowed_values)) valuestr = ", ".join(str(v) for v in sorted(allowed_values))
yield " {} = Literal[{}]".format(field.py_type, valuestr) yield " {} = Literal[{}]".format(field.py_inner_type, valuestr)
yield " except ImportError:" yield " except ImportError:"
yield " Dict, List, Optional = None, None, None # type: ignore" yield " Dict, List, Optional = None, None, None # type: ignore"
for field in all_enums: for field in all_enums:
yield " {} = None # type: ignore".format(field.py_type) yield " {} = None # type: ignore".format(field.py_inner_type)
yield "" yield ""
yield "" yield ""