Skip to content

Commit

Permalink
style: reformating code with ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
d3cryptofc committed Nov 5, 2024
1 parent e6c030f commit e10c524
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
7 changes: 2 additions & 5 deletions structer/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,5 @@ def str_value_oversized_error(field_type):
message = (
'`{}` value size must be {} bytes at most '
'(accents usually occupy more than one byte)'
).format(
type(field_type).__name__,
field_type._size
)
return ValueError(message)
).format(type(field_type).__name__, field_type._size)
return ValueError(message)
14 changes: 10 additions & 4 deletions structer/struct.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from types import MappingProxyType
from typing import ClassVar, Sequence, NoReturn
from typing import ClassVar, NoReturn, Sequence

from . import errors
from .field import Field
Expand Down Expand Up @@ -68,16 +68,22 @@ def __init__(self, **kwargs):
else:
field_value = field.type.decode(b'\0')

self.__struct_offsets__[field.name] = start_range, start_range + field.type.size
self.__struct_offsets__[field.name] = (
start_range,
start_range + field.type.size,
)
self.__setattr__(field.name, field_value)
setattr(
self, '__struct_size__', self.__struct_size__ + field.type.size
)

start_range += field.type.size

setattr(self, '__struct_offsets__', MappingProxyType(self.__struct_offsets__))

setattr(
self,
'__struct_offsets__',
MappingProxyType(self.__struct_offsets__),
)

def __len__(self):
return self.__struct_size__
Expand Down

0 comments on commit e10c524

Please sign in to comment.