Skip to content

Commit d5c4aab

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

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

devito/ir/iet/visitors.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,8 @@ def _post_visit(self, ret: Iterator[Node | object]) -> list[Node]:
11471147
def visit_object(self, o: object, flag: bool = False) -> Iterator[Node | object]:
11481148
yield self.SET_FLAG if flag else self.UNSET_FLAG
11491149

1150-
def visit_tuple(self, o: Sequence[Any], flag: bool = False) -> Iterator[Node | object]:
1150+
def visit_tuple(self, o: Sequence[Any],
1151+
flag: bool = False) -> Iterator[Node | object]:
11511152
for el in o:
11521153
for i in self._visit(el, flag=flag):
11531154
# New flag state is yielded at the end of child results

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)