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