| 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) |