Beispiel #1
0
 def _process(self, node):
     qn = anno.getanno(node, anno.Basic.QN)
     if qn in self.name_map:
         new_node = gast.Name(str(self.name_map[qn]), node.ctx, None)
         # All annotations get carried over.
         for k in anno.keys(node):
             anno.copyanno(node, new_node, k)
         return new_node
     return self.generic_visit(node)
Beispiel #2
0
 def _process(self, node):
   qn = anno.getanno(node, anno.Basic.QN)
   if qn in self.name_map:
     new_node = gast.Name(str(self.name_map[qn]), node.ctx, None)
     # All annotations get carried over.
     for k in anno.keys(node):
       anno.copyanno(node, new_node, k)
     return new_node
   return self.generic_visit(node)
Beispiel #3
0
  def test_basic(self):
    node = ast.Name()

    self.assertEqual(anno.keys(node), set())
    self.assertFalse(anno.hasanno(node, 'foo'))
    with self.assertRaises(AttributeError):
      anno.getanno(node, 'foo')

    anno.setanno(node, 'foo', 3)

    self.assertEqual(anno.keys(node), {'foo'})
    self.assertTrue(anno.hasanno(node, 'foo'))
    self.assertEqual(anno.getanno(node, 'foo'), 3)
    self.assertEqual(anno.getanno(node, 'bar', default=7), 7)

    anno.delanno(node, 'foo')

    self.assertEqual(anno.keys(node), set())
    self.assertFalse(anno.hasanno(node, 'foo'))
    with self.assertRaises(AttributeError):
      anno.getanno(node, 'foo')
    self.assertIsNone(anno.getanno(node, 'foo', default=None))