OLD | NEW |
(Empty) | |
| 1 """ |
| 2 Adds this import line: |
| 3 |
| 4 from builtins import XYZ |
| 5 |
| 6 for each of the functions XYZ that is used in the module. |
| 7 """ |
| 8 |
| 9 from __future__ import unicode_literals |
| 10 |
| 11 from lib2to3 import fixer_base |
| 12 from lib2to3.pygram import python_symbols as syms |
| 13 from lib2to3.fixer_util import Name, Call, in_special_context |
| 14 |
| 15 from libfuturize.fixer_util import touch_import_top |
| 16 |
| 17 # All builtins are: |
| 18 # from future.builtins.iterators import (filter, map, zip) |
| 19 # from future.builtins.misc import (ascii, chr, hex, input, isinstance, oct,
open, round, super) |
| 20 # from future.types import (bytes, dict, int, range, str) |
| 21 # We don't need isinstance any more. |
| 22 |
| 23 replaced_builtins = '''filter map zip |
| 24 ascii chr hex input next oct open round super |
| 25 bytes dict int range str'''.split() |
| 26 |
| 27 expression = '|'.join(["name='{0}'".format(name) for name in replaced_builtins]) |
| 28 |
| 29 |
| 30 class FixFutureBuiltins(fixer_base.BaseFix): |
| 31 BM_compatible = True |
| 32 run_order = 9 |
| 33 |
| 34 # Currently we only match uses as a function. This doesn't match e.g.: |
| 35 # if isinstance(s, str): |
| 36 # ... |
| 37 PATTERN = """ |
| 38 power< |
| 39 ({0}) trailer< '(' args=[any] ')' > |
| 40 rest=any* > |
| 41 """.format(expression) |
| 42 |
| 43 def transform(self, node, results): |
| 44 name = results["name"] |
| 45 touch_import_top(u'builtins', name.value, node) |
| 46 # name.replace(Name(u"input", prefix=name.prefix)) |
| 47 |
OLD | NEW |