1 | n/a | """Fixer for reload(). |
---|
2 | n/a | |
---|
3 | n/a | reload(s) -> imp.reload(s)""" |
---|
4 | n/a | |
---|
5 | n/a | # Local imports |
---|
6 | n/a | from .. import fixer_base |
---|
7 | n/a | from ..fixer_util import ImportAndCall, touch_import |
---|
8 | n/a | |
---|
9 | n/a | |
---|
10 | n/a | class FixReload(fixer_base.BaseFix): |
---|
11 | n/a | BM_compatible = True |
---|
12 | n/a | order = "pre" |
---|
13 | n/a | |
---|
14 | n/a | PATTERN = """ |
---|
15 | n/a | power< 'reload' |
---|
16 | n/a | trailer< lpar='(' |
---|
17 | n/a | ( not(arglist | argument<any '=' any>) obj=any |
---|
18 | n/a | | obj=arglist<(not argument<any '=' any>) any ','> ) |
---|
19 | n/a | rpar=')' > |
---|
20 | n/a | after=any* |
---|
21 | n/a | > |
---|
22 | n/a | """ |
---|
23 | n/a | |
---|
24 | n/a | def transform(self, node, results): |
---|
25 | n/a | if results: |
---|
26 | n/a | # I feel like we should be able to express this logic in the |
---|
27 | n/a | # PATTERN above but I don't know how to do it so... |
---|
28 | n/a | obj = results['obj'] |
---|
29 | n/a | if obj: |
---|
30 | n/a | if obj.type == self.syms.star_expr: |
---|
31 | n/a | return # Make no change. |
---|
32 | n/a | if (obj.type == self.syms.argument and |
---|
33 | n/a | obj.children[0].value == '**'): |
---|
34 | n/a | return # Make no change. |
---|
35 | n/a | names = ('imp', 'reload') |
---|
36 | n/a | new = ImportAndCall(node, results, names) |
---|
37 | n/a | touch_import(None, 'imp', node) |
---|
38 | n/a | return new |
---|