From 3d7e8d7c6c4502defce0b472ba6a99e649647ab2 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 30 Jan 2024 15:41:08 +0500 Subject: [PATCH] Fixed #4259 Result of DeepDiff contain ordered sets. Also added fallback for usual sets to lists just in case, should be safe. --- src/ifcdiff/ifcdiff.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/ifcdiff/ifcdiff.py b/src/ifcdiff/ifcdiff.py index 32286882d0..e41a9667ee 100755 --- a/src/ifcdiff/ifcdiff.py +++ b/src/ifcdiff/ifcdiff.py @@ -34,6 +34,7 @@ import ifcopenshell.util.placement import ifcopenshell.util.classification import ifcopenshell.util.representation from deepdiff import DeepDiff +from ordered_set import OrderedSet class IfcDiff: @@ -234,6 +235,12 @@ class IfcDiff: settings.set_context_ids(body_contexts) return settings + def json_dump_default(self, obj): + # result of DeepDiff may contain ordered sets + if isinstance(obj, (OrderedSet, set)): + return list(obj) + return json.JSONEncoder.default(None, obj) + def export(self, path): with open(path, "w", encoding="utf-8") as diff_file: json.dump( @@ -244,6 +251,7 @@ class IfcDiff: }, diff_file, indent=4, + default=self.json_dump_default, ) def get_precision(self):