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

Function replace_as_expression

tensorflow/python/autograph/pyct/templates.py:278–293  ·  view source on GitHub ↗

Variant of replace that generates expressions, instead of code blocks.

(template, **replacements)

Source from the content-addressed store, hash-verified

276
277
278def replace_as_expression(template, **replacements):
279 """Variant of replace that generates expressions, instead of code blocks."""
280 replacement = replace(template, **replacements)
281 if len(replacement) != 1:
282 raise ValueError(
283 'single expression expected; for more general templates use replace')
284 node, = replacement
285
286 if isinstance(node, gast.Expr):
287 return node.value
288 elif isinstance(node, gast.Name):
289 return node
290
291 raise ValueError(
292 'the template is expected to generate an expression or a name node;'
293 ' instead found %s' % node)

Callers

nothing calls this directly

Calls 1

replaceFunction · 0.85

Tested by

no test coverage detected