Skip to content

Commit 35383e4

Browse files
committed
Flatten out arithmetical and boolean operations
1 parent c4fa3e4 commit 35383e4

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

library/info.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,25 +365,30 @@ def get_arithmetic_middle(root):
365365

366366

367367
# Extract Left Middle Right from Boolean expressions
368+
def get_boolean(root):
369+
if not match_node(root,ast.BoolOp) or match_parent(root,ast.BoolOp):
370+
return None
371+
return root
372+
368373

369374
def get_boolean_left(root):
370-
if not match_node(root,ast.BoolOp):
375+
if not match_node(root,ast.BoolOp) or match_parent(root,ast.BoolOp):
371376
return None
372377
items = root.values
373378
if len(items)>=1:
374379
return items[0]
375380
return None
376381

377382
def get_boolean_right(root):
378-
if not match_node(root,ast.BoolOp):
383+
if not match_node(root,ast.BoolOp) or match_parent(root,ast.BoolOp):
379384
return None
380385
items = root.values
381386
if len(items)>=2:
382387
return items[-1]
383388
return None
384389

385390
def get_boolean_middle(root):
386-
if not match_node(root,ast.BoolOp):
391+
if not match_node(root,ast.BoolOp) or match_parent(root,ast.BoolOp):
387392
return None
388393
items = root.values
389394
if len(items)==3:

queries/big_roi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def standard(x):
120120
"attribute":((ast.Attribute),(),standard),
121121
"comparison":((ast.Compare),(),standard),
122122
"arithmetic":((ast.BinOp),(),get_arithmetic),
123-
"boolean":((ast.BoolOp),(),standard),
123+
"boolean":((ast.BoolOp),(),get_boolean),
124124

125125
"container":((ast.Compare),(),get_container_check),
126126
"member":((ast.Compare),(),get_member_check),

0 commit comments

Comments
 (0)