MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / matches

Function matches

tensorflow/python/autograph/pyct/ast_util.py:193–211  ·  view source on GitHub ↗

Basic pattern matcher for AST. The pattern may contain wildcards represented by the symbol '_'. A node matches a pattern if for every node in the tree, either there is a node of the same type in pattern, or a Name node with id='_'. Args: node: ast.AST pattern: ast.AST Returns:

(node, pattern)

Source from the content-addressed store, hash-verified

191
192
193def matches(node, pattern):
194 """Basic pattern matcher for AST.
195
196 The pattern may contain wildcards represented by the symbol '_'. A node
197 matches a pattern if for every node in the tree, either there is a node of
198 the same type in pattern, or a Name node with id='_'.
199
200 Args:
201 node: ast.AST
202 pattern: ast.AST
203 Returns:
204 bool
205 """
206 if isinstance(pattern, str):
207 pattern = parser.parse_str(pattern)
208
209 matcher = PatternMatcher(pattern)
210 matcher.visit(node)
211 return matcher.matches
212
213
214# TODO(mdan): Once we have error tracing, we may be able to just go to SSA.

Callers

nothing calls this directly

Calls 2

PatternMatcherClass · 0.85
visitMethod · 0.45

Tested by

no test coverage detected