mirror of
https://github.com/python/cpython.git
synced 2025-07-23 03:05:38 +00:00
Merged revisions 61596-61597 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r61596 | martin.v.loewis | 2008-03-18 23:43:46 -0500 (Di, 18 Mär 2008) | 2 lines Import lib2to3. ........ r61597 | martin.v.loewis | 2008-03-18 23:58:04 -0500 (Di, 18 Mär 2008) | 3 lines Initialized merge tracking via "svnmerge" with revisions "1-61595" from svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3 ........
This commit is contained in:
parent
c42bcbb1f0
commit
ef04c44e29
67 changed files with 11990 additions and 0 deletions
27
Lib/lib2to3/fixes/fix_numliterals.py
Normal file
27
Lib/lib2to3/fixes/fix_numliterals.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
"""Fixer that turns 1L into 1, 0755 into 0o755.
|
||||
"""
|
||||
# Copyright 2007 Georg Brandl.
|
||||
# Licensed to PSF under a Contributor Agreement.
|
||||
|
||||
# Local imports
|
||||
from ..pgen2 import token
|
||||
from .import basefix
|
||||
from .util import Number, set
|
||||
|
||||
|
||||
class FixNumliterals(basefix.BaseFix):
|
||||
# This is so simple that we don't need the pattern compiler.
|
||||
|
||||
def match(self, node):
|
||||
# Override
|
||||
return (node.type == token.NUMBER and
|
||||
(node.value.startswith("0") or node.value[-1] in "Ll"))
|
||||
|
||||
def transform(self, node, results):
|
||||
val = node.value
|
||||
if val[-1] in 'Ll':
|
||||
val = val[:-1]
|
||||
elif val.startswith('0') and val.isdigit() and len(set(val)) > 1:
|
||||
val = "0o" + val[1:]
|
||||
|
||||
return Number(val, prefix=node.get_prefix())
|
Loading…
Add table
Add a link
Reference in a new issue