Local hacks to compile and monkey patch issues in the Python world

All AI generated slop. Do NOT trust these "fixes". It's just to get it
working on my machine.
This commit is contained in:
Dion Moult
2026-04-11 16:27:06 +10:00
parent b40e4378b3
commit 543d9f8588
7 changed files with 406 additions and 4 deletions
@@ -103,7 +103,7 @@ class entity_instance_mixin:
idx = self.get_argument_index(name)
return self.get_argument(idx)
elif attr_cat == INVERSE:
vs = self.get_inverse(name)
vs = self.get_inverses_by_declaration(name)
if settings.unpack_non_aggregate_inverses:
schema_name = self.is_a(True).split(".")[0]
ent: ifcopenshell_wrapper.entity
@@ -213,11 +213,17 @@ class entity_instance_mixin:
return value
def __eq__(self, other: entity_instance_mixin) -> bool:
if not isinstance(self, type(other)):
if other is None or not isinstance(other, entity_instance_mixin):
return False
else:
raise NotImplementedError
def __ne__(self, other: entity_instance_mixin) -> bool:
if other is None or not isinstance(other, entity_instance_mixin):
return True
else:
raise NotImplementedError
def is_entity(self) -> bool:
"""Tests whether the instance is an entity type as opposed to a simple data type.
@@ -395,3 +401,45 @@ class entity_instance_mixin:
assert return_type is dict
assert len(ignore) == 0
return ifcopenshell_wrapper.get_info_cpp(self, recursive, include_identifier)
# Alias for backwards compatibility — external code imports this name.
entity_instance = entity_instance_mixin
# Monkey-patch SWIG's __eq__, __ne__, __lt__ on the generated entity_instance
# class to guard against None / non-entity arguments. SWIG generates these
# directly on the class (overriding the mixin), and they pass arguments straight
# to C++ which rejects null references.
# Deferred until after ifcopenshell_wrapper finishes loading to avoid circular import.
_swig_comparisons_patched = False
def _patch_swig_comparisons():
global _swig_comparisons_patched
if _swig_comparisons_patched:
return
_swig_cls = ifcopenshell_wrapper.entity_instance
_orig_eq = _swig_cls.__eq__
_orig_ne = _swig_cls.__ne__
_orig_lt = _swig_cls.__lt__
def _safe_eq(self, other):
if other is None or not isinstance(other, _swig_cls):
return NotImplemented
return _orig_eq(self, other)
def _safe_ne(self, other):
if other is None or not isinstance(other, _swig_cls):
return NotImplemented
return _orig_ne(self, other)
def _safe_lt(self, other):
if other is None or not isinstance(other, _swig_cls):
return NotImplemented
return _orig_lt(self, other)
_swig_cls.__eq__ = _safe_eq
_swig_cls.__ne__ = _safe_ne
_swig_cls.__lt__ = _safe_lt
_swig_comparisons_patched = True