ยปCore Development>Code coverage>Lib/lib2to3/fixes/fix_numliterals.py

Python code coverage for Lib/lib2to3/fixes/fix_numliterals.py

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