mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-27 10:51:13 +00:00
Fix rule compilation regarding indeterminate #7529
This commit is contained in:
@@ -750,6 +750,14 @@ class AttributeGetattrTransformer(ast.NodeTransformer):
|
|||||||
if node.attr == "create_entity":
|
if node.attr == "create_entity":
|
||||||
return node
|
return node
|
||||||
|
|
||||||
|
if node.attr.startswith("__"):
|
||||||
|
return node
|
||||||
|
|
||||||
|
# Don't rewrite at module scope (top-level, no indent)
|
||||||
|
enclosing_stmt = next((p for p in parents if isinstance(p, ast.stmt)), None)
|
||||||
|
if enclosing_stmt is not None and isinstance(getattr(enclosing_stmt, "parent", None), ast.Module):
|
||||||
|
return node
|
||||||
|
|
||||||
new_value = self.visit(node.value)
|
new_value = self.visit(node.value)
|
||||||
|
|
||||||
# Replace the Attribute node with a call to the built-in `getattr` function
|
# Replace the Attribute node with a call to the built-in `getattr` function
|
||||||
@@ -842,18 +850,21 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
print(
|
print(
|
||||||
"""
|
"""
|
||||||
|
def is_indeterminate(v):
|
||||||
|
return v is None or type(v).__name__ == 'indeterminate_type'
|
||||||
|
|
||||||
def exists(v):
|
def exists(v):
|
||||||
if callable(v):
|
if callable(v):
|
||||||
try: return v() is not None
|
try: return v() is not None
|
||||||
except IndexError as e: return False
|
except IndexError as e: return False
|
||||||
else: return v is not None
|
else: return not is_indeterminate(v)
|
||||||
""",
|
""",
|
||||||
"\n",
|
"\n",
|
||||||
file=output,
|
file=output,
|
||||||
sep="\n",
|
sep="\n",
|
||||||
)
|
)
|
||||||
print(
|
print(
|
||||||
"def nvl(v, default): return v if v is not None else default",
|
"def nvl(v, default): return v if not is_indeterminate(v) else default",
|
||||||
"\n",
|
"\n",
|
||||||
file=output,
|
file=output,
|
||||||
sep="\n",
|
sep="\n",
|
||||||
@@ -871,14 +882,14 @@ def is_entity(inst):
|
|||||||
def express_len(v):
|
def express_len(v):
|
||||||
if isinstance(v, ifcopenshell.entity_instance) and not is_entity(v):
|
if isinstance(v, ifcopenshell.entity_instance) and not is_entity(v):
|
||||||
v = v[0]
|
v = v[0]
|
||||||
elif v is None or v is INDETERMINATE:
|
elif is_indeterminate(v):
|
||||||
return INDETERMINATE
|
return INDETERMINATE
|
||||||
return len(v)
|
return len(v)
|
||||||
|
|
||||||
old_range = range
|
old_range = range
|
||||||
|
|
||||||
def range(*args):
|
def range(*args):
|
||||||
if INDETERMINATE in args:
|
if any(map(is_indeterminate, args)):
|
||||||
return
|
return
|
||||||
yield from old_range(*args)
|
yield from old_range(*args)
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user