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

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

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