From 55baf2db3554c8043eb7acbe694717e7a36d7e8c Mon Sep 17 00:00:00 2001 From: Diego Argueta Date: Mon, 13 Feb 2023 19:29:15 -0800 Subject: [PATCH] Work around weird bug in Python 3.7 and 3.8 ChainMap --- binobj/structures.py | 8 +++++--- tox.ini | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/binobj/structures.py b/binobj/structures.py index 65273a7a..ed5caabb 100644 --- a/binobj/structures.py +++ b/binobj/structures.py @@ -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( diff --git a/tox.ini b/tox.ini index 024bdc7d..1e07f25f 100644 --- a/tox.ini +++ b/tox.ini @@ -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