Skip to content

Commit

Permalink
Work around weird bug in Python 3.7 and 3.8 ChainMap
Browse files Browse the repository at this point in the history
  • Loading branch information
dargueta committed Feb 14, 2023
1 parent b4d17d8 commit 55baf2d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
8 changes: 5 additions & 3 deletions binobj/structures.py
Expand Up @@ -349,15 +349,17 @@ def _to_dict_whatever_possible(self) -> MutableMapping[str, Any]:
have no dependencies and can serialize themselves (e.g. Bytes and sized int
fields). This allows us to resolve forward references.
"""
dct = collections.ChainMap({}, self)
dct = {}

for field in self.__binobj_struct__.components.values():
try:
dct[field.name] = field.compute_value_for_dump(dct)
dct[field.name] = field.compute_value_for_dump(
typing.cast(StrDict, self)
)
except errors.Error:
continue

return dct
return collections.ChainMap(dct, self)

@classmethod
def from_stream(
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Expand Up @@ -60,6 +60,7 @@ per_file_ignores =
tests/*:D
unused_arguments_ignore_abstract_functions = true
unused_arguments_ignore_overload_functions = true
unused_arguments_ignore_override_functions = true
unused_arguments_ignore_stub_functions = true
unused_arguments_ignore_dunder = true

Expand Down

0 comments on commit 55baf2d

Please sign in to comment.