Skip to content

Commit c67bb40

Browse files
committed
misc: flake8 fix + match/case for search
1 parent ae802f6 commit c67bb40

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

devito/ir/iet/visitors.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,7 @@ def visit_Node(self, o: Node, flag: bool = False) -> LazyVisit[Node, bool]:
11941194

11951195
# Update the flag if we found a stop
11961196
flag &= (o is not self.stop)
1197+
11971198
return flag
11981199

11991200

devito/symbolics/search.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,15 @@ def search(exprs: Expression | Iterable[Expression],
104104
# Search doesn't actually use a BFS (rather, a preorder DFS), but the terminology
105105
# is retained in this function's parameters for backwards compatibility
106106
searcher = Search(Q, deep)
107-
if visit == 'dfs':
108-
_search = searcher.visit_postorder
109-
elif visit == 'bfs':
110-
_search = searcher.visit_preorder
111-
elif visit == 'bfs_first_hit':
112-
_search = searcher.visit_preorder_first_hit
113-
else:
114-
raise ValueError(f"Unknown visit mode '{visit}'")
107+
match visit:
108+
case 'dfs':
109+
_search = searcher.visit_postorder
110+
case 'bfs':
111+
_search = searcher.visit_preorder
112+
case 'bfs_first_hit':
113+
_search = searcher.visit_preorder_first_hit
114+
case _:
115+
raise ValueError(f"Unknown visit mode '{visit}'")
115116

116117
exprs = filter(lambda e: isinstance(e, sympy.Basic), as_tuple(exprs))
117118
found = modes[mode](chain(*map(_search, exprs)))

0 commit comments

Comments
 (0)