mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-12 18:43:26 +00:00
Compare entity instances in one file by identity again
entity_instance.file is a property backed by a fresh SWIG wrapper on every access, and ifcopenshell::file had no __eq__, so `self.file != other.file` in entity_instance.__eq__ compared two throwaway wrappers and was always true - even for an instance against itself. Every entity comparison therefore took the deep get_info() branch, making distinct but structurally identical instances compare equal and leaving the final `return False` unreachable. Bonsai's TestAddRepresentationItemToShapeAspect showed this as two separate IfcShapeAspects being treated as one, so the stale aspect was never removed. Restore the file_pointer() pair that was commented out on both ifcopenshell::file and express::Base - IfcParseWrapper.i already described it as the way to "trace file ownership of instances on the python side" - and give file the __eq__/__hash__ it was missing. The express::Base one needs $self->file() now that file_ lives on instance_data. This also repairs rocksdb_lazy_instance.__eq__, which already called file_pointer(). EXPRESS `=` is value comparison and `:=:` is instance comparison, but rule_compiler emits `==` for both (see the @todo on process_rel_op), and derived attributes build their operands in the shared global file, so rules compare same-file instances and need value semantics. Restore those for the duration of rule execution with settings.compare_instances_by_value, alongside the existing unpack_non_aggregate_inverses. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -75,6 +75,20 @@ def test_equality():
|
||||
assert f[1] == g[1]
|
||||
g[1].Coordinates = (1.0, 0.0)
|
||||
assert f[1] != g[1]
|
||||
f.createIfcCartesianPoint((0.0, 0.0))
|
||||
assert f[1] == f[1]
|
||||
assert f[1] != f[2]
|
||||
|
||||
|
||||
def test_equality_of_owning_file():
|
||||
f = ifcopenshell.file()
|
||||
g = ifcopenshell.file()
|
||||
f.createIfcCartesianPoint((0.0, 0.0))
|
||||
f.createIfcCartesianPoint((0.0, 0.0))
|
||||
g.createIfcCartesianPoint((0.0, 0.0))
|
||||
assert f[1].file == f[1].file
|
||||
assert f[1].file == f[2].file
|
||||
assert f[1].file != g[1].file
|
||||
|
||||
|
||||
def test_setting_logical():
|
||||
|
||||
Reference in New Issue
Block a user