Coverage for /pythoncovmergedfiles/medio/medio/src/underscore/underscore/constant_changer.py: 75%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

12 statements  

1# Copyright (c) 2013 Huan Do, http://huan.do 

2 

3import ast 

4 

5from utils import value_of 

6 

7class ConstantChanger(ast.NodeTransformer): 

8 

9 def __init__(self, env): 

10 self.env = env 

11 

12 def visit_Constant(self, node): 

13 if not hasattr(node, 'isdoc'): 

14 value = value_of(node) 

15 return ast.Name(id=self.env.constants[value].name) 

16 else: 

17 return node 

18 

19 visit_Num = visit_Str = visit_Constant