mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-26 18:21:59 +00:00
Map None -> Indeterminate to prevent iterating over none in non-shortcircuiting rule execution #7501
This commit is contained in:
@@ -738,7 +738,7 @@ class AttributeGetattrTransformer(ast.NodeTransformer):
|
|||||||
while n := getattr(n, "parent", 0):
|
while n := getattr(n, "parent", 0):
|
||||||
parents.append(n)
|
parents.append(n)
|
||||||
|
|
||||||
custom_funcs = "is_entity", "usedin", "express_len", "express_getitem", "typeof"
|
custom_funcs = "is_entity", "usedin", "express_len", "express_getitem", "typeof", "express_getattr"
|
||||||
function_defs = [p.name for p in parents if isinstance(p, ast.FunctionDef)]
|
function_defs = [p.name for p in parents if isinstance(p, ast.FunctionDef)]
|
||||||
if any(fn in function_defs for fn in custom_funcs):
|
if any(fn in function_defs for fn in custom_funcs):
|
||||||
return node
|
return node
|
||||||
@@ -755,7 +755,7 @@ class AttributeGetattrTransformer(ast.NodeTransformer):
|
|||||||
# 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
|
||||||
return ast.copy_location(
|
return ast.copy_location(
|
||||||
ast.Call(
|
ast.Call(
|
||||||
func=ast.Name(id="getattr", ctx=ast.Load()),
|
func=ast.Name(id="express_getattr", ctx=ast.Load()),
|
||||||
args=[
|
args=[
|
||||||
new_value,
|
new_value,
|
||||||
ast.Str(s=node.attr),
|
ast.Str(s=node.attr),
|
||||||
@@ -772,7 +772,7 @@ class AttributeGetattrTransformer(ast.NodeTransformer):
|
|||||||
while n := getattr(n, "parent", 0):
|
while n := getattr(n, "parent", 0):
|
||||||
parents.append(n)
|
parents.append(n)
|
||||||
|
|
||||||
custom_funcs = "is_entity", "usedin", "express_len", "express_getitem", "typeof"
|
custom_funcs = "is_entity", "usedin", "express_len", "express_getitem", "typeof", "express_getattr"
|
||||||
function_defs = [p.name for p in parents if isinstance(p, ast.FunctionDef)]
|
function_defs = [p.name for p in parents if isinstance(p, ast.FunctionDef)]
|
||||||
if any(fn in function_defs for fn in custom_funcs):
|
if any(fn in function_defs for fn in custom_funcs):
|
||||||
return node
|
return node
|
||||||
@@ -937,6 +937,14 @@ def express_getitem(aggr, idx, default):
|
|||||||
except IndexError as e: return None
|
except IndexError as e: return None
|
||||||
|
|
||||||
|
|
||||||
|
def express_getattr(aggr, name, default):
|
||||||
|
v = getattr(aggr, name, default)
|
||||||
|
if v is None:
|
||||||
|
return default
|
||||||
|
else:
|
||||||
|
return v
|
||||||
|
|
||||||
|
|
||||||
EXPRESS_ONE_BASED_INDEXING = 1
|
EXPRESS_ONE_BASED_INDEXING = 1
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from codegen import indent
|
|||||||
|
|
||||||
|
|
||||||
def reverse_compile(s):
|
def reverse_compile(s):
|
||||||
return re.sub(
|
return re.sub(r'\bself\b', 'SELF', re.sub(
|
||||||
r"\s*\-\s*EXPRESS_ONE_BASED_INDEXING",
|
r"\s*\-\s*EXPRESS_ONE_BASED_INDEXING",
|
||||||
"",
|
"",
|
||||||
re.sub(
|
re.sub(
|
||||||
@@ -22,11 +22,11 @@ def reverse_compile(s):
|
|||||||
.replace("len(", "SIZEOF(")
|
.replace("len(", "SIZEOF(")
|
||||||
.replace("assert ", "")
|
.replace("assert ", "")
|
||||||
.replace(" is not False", "")
|
.replace(" is not False", "")
|
||||||
.replace("getattr(", "")
|
.replace("express_getattr(", "")
|
||||||
.replace("express_getitem(", ""),
|
.replace("express_getitem(", ""),
|
||||||
)[::-1],
|
)[::-1],
|
||||||
)[::-1],
|
)[::-1],
|
||||||
)
|
))
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|||||||
Reference in New Issue
Block a user