Skip to content

Commit

Permalink
satisfy some pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
kizzx2 committed Nov 3, 2024
1 parent d62b0cd commit f2a068a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[MASTER]
extension-pkg-whitelist=lxml
disable=line-too-long,too-many-lines
disable=line-too-long,too-many-lines,too-many-locals,too-many-positional-arguments,too-many-branches,too-many-return-statements,too-many-instance-attributes,invalid-name,missing-function-docstring,missing-class-docstring,too-many-statements,too-many-arguments,missing-module-docstring
42 changes: 19 additions & 23 deletions sbe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,10 @@ def return_value(self, buf: memoryview, offset: int, _parent: Optional['WrappedC
if self.enum:
return self.enum.find_name_by_value(
rv.decode("ascii") if isinstance(rv, bytes) else str(rv))
elif self.set_:
if self.set_:
return self.set_.find_name_by_value(
rv.decode("ascii") if isinstance(rv, bytes) else str(rv))
elif self.value.endswith("s"):
if self.value.endswith("s"):
return rv.split(b'\x00', 1)[0].decode('ascii', errors='ignore').strip()

return rv
Expand All @@ -197,12 +197,11 @@ def unpack(self, buf: memoryview):
def __repr__(self):
if self.enum:
return f"{self.enum.name}@{self.offset}"
elif isinstance(self.value, WrappedComposite):
if isinstance(self.value, WrappedComposite):
return f"{self.value.name}@{self.offset}"
elif self.value in FORMAT_TO_TYPE:
if self.value in FORMAT_TO_TYPE:
return f"{FORMAT_TO_TYPE[self.value].value}@{self.offset}"
else:
return f"{self.value}@{self.offset}"
return f"{self.value}@{self.offset}"


@dataclass
Expand Down Expand Up @@ -232,8 +231,7 @@ def find_value_by_name(self, name: Optional[str]) -> str:
val = next(x for x in self.valid_values if x.name == name).value
if self.encodingType == EnumEncodingType.CHAR or (isinstance(self.encodingType, Type) and self.encodingType.primitiveType == PrimitiveType.CHAR):
return val.encode()
else:
return int(val)
return int(val)

def find_name_by_value(self, val: str) -> str:
if val not in (x.value for x in self.valid_values):
Expand All @@ -260,7 +258,7 @@ def size(self):
else:
sz += FORMAT_SIZES[t.primitiveType]
else:
assert(isinstance(t, Composite))
assert isinstance(t, Composite)
sz += t.size()
return sz

Expand Down Expand Up @@ -314,8 +312,7 @@ def __init__(self, name: str, id_: str, type_: Union[PrimitiveType, str]):
def __repr__(self):
if isinstance(self.type, PrimitiveType):
return f"<{self.name} ({self.type.value})>"
else:
return f"<{self.name} ({self.type})>"
return f"<{self.name} ({self.type})>"


@dataclass
Expand Down Expand Up @@ -587,10 +584,10 @@ def _unpack_format(
buffer_cursor.val += FORMAT_SIZES[type_]
return prefix + FORMAT[type_]

elif isinstance(type_, Field):
if isinstance(type_, Field):
return _unpack_format(schema, type_.type, '', buffer, buffer_cursor)

elif isinstance(type_, Group):
if isinstance(type_, Group):
if len(buffer[buffer_cursor.val:]) == 0:
return ''

Expand All @@ -608,7 +605,7 @@ def _unpack_format(

return rv

elif isinstance(type_, Type):
if isinstance(type_, Type):
if type_.presence == Presence.CONSTANT:
return ''
if type_.padding > 0:
Expand All @@ -619,12 +616,12 @@ def _unpack_format(
if buffer_cursor:
buffer_cursor.val += type_.length
return prefix + f"{type_.length}s"
else:
if buffer_cursor:
buffer_cursor.val += FORMAT_SIZES[type_.primitiveType]
return prefix + FORMAT[type_.primitiveType]

elif isinstance(type_, (Set, Enum)):
if buffer_cursor:
buffer_cursor.val += FORMAT_SIZES[type_.primitiveType]
return prefix + FORMAT[type_.primitiveType]

if isinstance(type_, (Set, Enum)):
if type_.presence == Presence.CONSTANT:
return ''
if isinstance(type_.encodingType, (PrimitiveType, EnumEncodingType, SetEncodingType)):
Expand All @@ -640,7 +637,7 @@ def _unpack_format(

return _unpack_format(schema, type_.encodingType, '', buffer, buffer_cursor)

elif isinstance(type_, Composite):
if isinstance(type_, Composite):
return prefix + ''.join(_unpack_format(schema, t, '', buffer, buffer_cursor) for t in type_.types)


Expand Down Expand Up @@ -832,8 +829,7 @@ def _resolve_ref_type(t: RefType, composite: Composite):
if isinstance(parent, Schema):
if t.type in parent.types:
return parent.types[t.type]
else:
assert False, f"RefType '{t.type}' not found in schema"
assert False, f"RefType '{t.type}' not found in schema"
else:
t1 = next((x for x in parent.types if x.name == t.type), None)
if t1 is not None:
Expand Down Expand Up @@ -1177,7 +1173,7 @@ def _parse_schema_impl(doc, only_tags: Optional[list] = None, extra_types: Optio
assert isinstance(stack[-1], Set)
stack[-1].choices.append(x)

elif tag == "field" or tag=="data":
elif tag in ('field', 'data'):
if action == "start":
assert len(elem) == 0

Expand Down

0 comments on commit f2a068a

Please sign in to comment.