Hacks and fixes to get python code back in reasonable state

This commit is contained in:
Thomas Krijnen
2026-01-10 10:21:09 +01:00
parent 69a4ad35a1
commit 5c9213426f
5 changed files with 60 additions and 31 deletions
@@ -87,10 +87,6 @@ class entity_instance_mixin:
print(wall.__class__) # <class 'ifcopenshell.entity_instance'>
"""
@property
def file(self):
raise NotImplementedError
def __getattr__(self, name: str) -> Any:
if name in ("this", "thisown") or name.startswith("_swig_"):
return object.__getattr__(self, name)
@@ -300,15 +296,6 @@ class entity_instance_mixin:
__rge__ = functools.partialmethod(compare, op=operator.ge, reverse=True)
__rgt__ = functools.partialmethod(compare, op=operator.gt, reverse=True)
def __hash__(self):
# Proper entity instances have a stable identity by means of the numeric
# step id. Selected type instances (such as IfcPropertySingleValue.NominalValue
# always have id=0, so we hash <type, value, file pointer>
if id_ := self.id():
return hash((id_, self.file_pointer()))
else:
return hash((self.is_a(), self[0], self.file_pointer()))
def __dir__(self):
return sorted(
set(
+23 -6
View File
@@ -504,13 +504,30 @@ class file_mixin:
to_delete: Union[set[ifcopenshell.entity_instance], None] = None
"""Entities for batch removal."""
registry = {}
def post_init(self, iden):
if state := self.registry.get(iden):
self.state = state
else:
self.state = self.registry[iden] = [[],[],None]
@property
def history(self):
return self.state[0]
@property
def future(self):
return self.state[1]
@property
def transaction(self):
return self.state[2]
def post_init(self):
self.history = []
self.future = []
self.transaction: Optional[Transaction] = None
@transaction.setter
def transaction(self, v):
self.state[2] = v
def set_history_size(self, size: int) -> None:
self.history_size = size
while len(self.history) > self.history_size:
@@ -670,7 +687,7 @@ class file_mixin:
if attr[0:6] == "create":
return functools.partial(self.create_entity, attr[6:])
else:
return getattr(self, attr)
raise AttributeError
def __getitem__(self, key: Union[numbers.Integral, str, bytes]) -> entity_instance:
if isinstance(key, numbers.Integral):
@@ -20,7 +20,7 @@
import time
import uuid
from .file import file
from ifcopenshell import file
from .guid import compress
from .ifcopenshell_wrapper import version
from typing import Optional
@@ -22,7 +22,7 @@ import ifcopenshell
import ifcopenshell.ifcopenshell_wrapper as W
import ifcopenshell.util.schema
import ifcopenshell.util.type
from ifcopenshell.entity_instance import entity_instance
from ifcopenshell import entity_instance
from functools import lru_cache
from typing import Optional, Literal, NamedTuple, Union