Mercurial > repos > guerler > springsuite
comparison planemo/lib/python3.7/site-packages/libfuturize/fixes/fix_future_builtins.py @ 1:56ad4e20f292 draft
"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author | guerler |
---|---|
date | Fri, 31 Jul 2020 00:32:28 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:d30785e31577 | 1:56ad4e20f292 |
---|---|
1 """ | |
2 For the ``future`` package. | |
3 | |
4 Adds this import line:: | |
5 | |
6 from builtins import XYZ | |
7 | |
8 for each of the functions XYZ that is used in the module. | |
9 | |
10 Adds these imports after any other imports (in an initial block of them). | |
11 """ | |
12 | |
13 from __future__ import unicode_literals | |
14 | |
15 from lib2to3 import fixer_base | |
16 from lib2to3.pygram import python_symbols as syms | |
17 from lib2to3.fixer_util import Name, Call, in_special_context | |
18 | |
19 from libfuturize.fixer_util import touch_import_top | |
20 | |
21 # All builtins are: | |
22 # from future.builtins.iterators import (filter, map, zip) | |
23 # from future.builtins.misc import (ascii, chr, hex, input, isinstance, oct, open, round, super) | |
24 # from future.types import (bytes, dict, int, range, str) | |
25 # We don't need isinstance any more. | |
26 | |
27 replaced_builtin_fns = '''filter map zip | |
28 ascii chr hex input next oct | |
29 bytes range str raw_input'''.split() | |
30 # This includes raw_input as a workaround for the | |
31 # lib2to3 fixer for raw_input on Py3 (only), allowing | |
32 # the correct import to be included. (Py3 seems to run | |
33 # the fixers the wrong way around, perhaps ignoring the | |
34 # run_order class attribute below ...) | |
35 | |
36 expression = '|'.join(["name='{0}'".format(name) for name in replaced_builtin_fns]) | |
37 | |
38 | |
39 class FixFutureBuiltins(fixer_base.BaseFix): | |
40 BM_compatible = True | |
41 run_order = 7 | |
42 | |
43 # Currently we only match uses as a function. This doesn't match e.g.: | |
44 # if isinstance(s, str): | |
45 # ... | |
46 PATTERN = """ | |
47 power< | |
48 ({0}) trailer< '(' [arglist=any] ')' > | |
49 rest=any* > | |
50 | | |
51 power< | |
52 'map' trailer< '(' [arglist=any] ')' > | |
53 > | |
54 """.format(expression) | |
55 | |
56 def transform(self, node, results): | |
57 name = results["name"] | |
58 touch_import_top(u'builtins', name.value, node) | |
59 # name.replace(Name(u"input", prefix=name.prefix)) |