MCPcopy Index your code
hub / github.com/python/cpython / RewriteSymbolics

Class RewriteSymbolics

Lib/inspect.py:2206–2237  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2204 raise ValueError
2205
2206 class RewriteSymbolics(ast.NodeTransformer):
2207 def visit_Attribute(self, node):
2208 a = []
2209 n = node
2210 while isinstance(n, ast.Attribute):
2211 a.append(n.attr)
2212 n = n.value
2213 if not isinstance(n, ast.Name):
2214 raise ValueError
2215 a.append(n.id)
2216 value = ".".join(reversed(a))
2217 return wrap_value(value)
2218
2219 def visit_Name(self, node):
2220 if not isinstance(node.ctx, ast.Load):
2221 raise ValueError()
2222 return wrap_value(node.id)
2223
2224 def visit_BinOp(self, node):
2225 # Support constant folding of a couple simple binary operations
2226 # commonly used to define default values in text signatures
2227 left = self.visit(node.left)
2228 right = self.visit(node.right)
2229 if not isinstance(left, ast.Constant) or not isinstance(right, ast.Constant):
2230 raise ValueError
2231 if isinstance(node.op, ast.Add):
2232 return ast.Constant(left.value + right.value)
2233 elif isinstance(node.op, ast.Sub):
2234 return ast.Constant(left.value - right.value)
2235 elif isinstance(node.op, ast.BitOr):
2236 return ast.Constant(left.value | right.value)
2237 raise ValueError
2238
2239 def p(name_node, default_node, default=empty):
2240 name = parse_name(name_node)

Callers 1

pFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…