MCPcopy
hub / github.com/pytest-dev/pytest / visit_NamedExpr

Method visit_NamedExpr

src/_pytest/assertion/rewrite.py:966–976  ·  view source on GitHub ↗
(self, name: ast.NamedExpr)

Source from the content-addressed store, hash-verified

964 return self.statements
965
966 def visit_NamedExpr(self, name: ast.NamedExpr) -> tuple[ast.NamedExpr, str]:
967 # This method handles the 'walrus operator' repr of the target
968 # name if it's a local variable or _should_repr_global_name()
969 # thinks it's acceptable.
970 locs = ast.Call(self.builtin("locals"), [], [])
971 target_id = name.target.id
972 inlocs = ast.Compare(ast.Constant(target_id), [ast.In()], [locs])
973 dorepr = self.helper("_should_repr_global_name", name)
974 test = ast.BoolOp(ast.Or(), [inlocs, dorepr])
975 expr = ast.IfExp(test, self.display(name), ast.Constant(target_id))
976 return name, self.explanation_param(expr)
977
978 def visit_Name(self, name: ast.Name) -> tuple[ast.Name, str]:
979 # Display the repr of the name if it's a local variable or

Callers

nothing calls this directly

Calls 4

builtinMethod · 0.95
helperMethod · 0.95
displayMethod · 0.95
explanation_paramMethod · 0.95

Tested by

no test coverage detected