mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
add fixer for reload() -> imp.reload() (closes #11797)\n\nPatch by Laurie Clark-Michalek and Berker Peksag
This commit is contained in:
parent
e7f2186f99
commit
448e81b2da
7 changed files with 120 additions and 18 deletions
28
Lib/lib2to3/fixes/fix_reload.py
Normal file
28
Lib/lib2to3/fixes/fix_reload.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
"""Fixer for reload().
|
||||
|
||||
reload(s) -> imp.reload(s)"""
|
||||
|
||||
# Local imports
|
||||
from .. import fixer_base
|
||||
from ..fixer_util import ImportAndCall, touch_import
|
||||
|
||||
|
||||
class FixReload(fixer_base.BaseFix):
|
||||
BM_compatible = True
|
||||
order = "pre"
|
||||
|
||||
PATTERN = """
|
||||
power< 'reload'
|
||||
trailer< lpar='('
|
||||
( not(arglist | argument<any '=' any>) obj=any
|
||||
| obj=arglist<(not argument<any '=' any>) any ','> )
|
||||
rpar=')' >
|
||||
after=any*
|
||||
>
|
||||
"""
|
||||
|
||||
def transform(self, node, results):
|
||||
names = ('imp', 'reload')
|
||||
new = ImportAndCall(node, results, names)
|
||||
touch_import(None, 'imp', node)
|
||||
return new
|
Loading…
Add table
Add a link
Reference in a new issue