Home | History | Annotate | Download | only in fixes
      1 """Fixer that turns 1L into 1, 0755 into 0o755.
      2 """
      3 # Copyright 2007 Georg Brandl.
      4 # Licensed to PSF under a Contributor Agreement.
      5 
      6 # Local imports
      7 from ..pgen2 import token
      8 from .. import fixer_base
      9 from ..fixer_util import Number
     10 
     11 
     12 class FixNumliterals(fixer_base.BaseFix):
     13     # This is so simple that we don't need the pattern compiler.
     14 
     15     _accept_type = token.NUMBER
     16 
     17     def match(self, node):
     18         # Override
     19         return (node.value.startswith(u"0") or node.value[-1] in u"Ll")
     20 
     21     def transform(self, node, results):
     22         val = node.value
     23         if val[-1] in u'Ll':
     24             val = val[:-1]
     25         elif val.startswith(u'0') and val.isdigit() and len(set(val)) > 1:
     26             val = u"0o" + val[1:]
     27 
     28         return Number(val, prefix=node.prefix)
     29