MCPcopy Create free account
hub / github.com/ipython/ipython / Negator

Class Negator

IPython/core/tests/test_interactiveshell.py:619–631  ·  view source on GitHub ↗

Negates all number literals in an AST.

Source from the content-addressed store, hash-verified

617 tt.ipexec_validate(self.fname, out)
618
619class Negator(ast.NodeTransformer):
620 """Negates all number literals in an AST."""
621
622 # for python 3.7 and earlier
623 def visit_Num(self, node):
624 node.n = -node.n
625 return node
626
627 # for python 3.8+
628 def visit_Constant(self, node):
629 if isinstance(node.value, int):
630 return self.visit_Num(node)
631 return node
632
633class TestAstTransform(unittest.TestCase):
634 def setUp(self):

Callers 1

setUpMethod · 0.85

Calls

no outgoing calls

Tested by 1

setUpMethod · 0.68