Some minor consistency changes

- replace some usages of `==` with `is`
- use available constants instead of magic strings for type names

Co-authored-by: nat <nat.noordanus@gmail.com>
This commit is contained in:
James 2020-07-12 15:07:27 +01:00 committed by GitHub
parent 2585a07fcf
commit cbd3437080
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -668,7 +668,7 @@ class Message(ABC):
elif t.__origin__ in (list, List):
# This is some kind of list (repeated) field.
return list
elif t.__origin__ == Union and t.__args__[1] == type(None):
elif t.__origin__ is Union and t.__args__[1] is type(None):
# This is an optional (wrapped) field. For setting the default we
# really don't care what kind of field it is.
return type(None)
@ -748,10 +748,10 @@ class Message(ABC):
pos = 0
value = []
while pos < len(parsed.value):
if meta.proto_type in ["float", "fixed32", "sfixed32"]:
if meta.proto_type in [TYPE_FLOAT, TYPE_FIXED32, TYPE_SFIXED32]:
decoded, pos = parsed.value[pos : pos + 4], pos + 4
wire_type = WIRE_FIXED_32
elif meta.proto_type in ["double", "fixed64", "sfixed64"]:
elif meta.proto_type in [TYPE_DOUBLE, TYPE_FIXED64, TYPE_SFIXED64]:
decoded, pos = parsed.value[pos : pos + 8], pos + 8
wire_type = WIRE_FIXED_64
else: