summaryrefslogtreecommitdiffstats
path: root/Lib/lib2to3/fixer_util.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2012-12-08 03:44:10 (GMT)
committerBenjamin Peterson <benjamin@python.org>2012-12-08 03:44:10 (GMT)
commit448e81b2da41e2ad89302cc8cb384795f9f6306c (patch)
tree97798e92a82e2a2bc27085ec73eff1675a090c42 /Lib/lib2to3/fixer_util.py
parente7f2186f994f84e050b869559132d28d4fe26614 (diff)
downloadcpython-448e81b2da41e2ad89302cc8cb384795f9f6306c.zip
cpython-448e81b2da41e2ad89302cc8cb384795f9f6306c.tar.gz
cpython-448e81b2da41e2ad89302cc8cb384795f9f6306c.tar.bz2
add fixer for reload() -> imp.reload() (closes #11797)\n\nPatch by Laurie Clark-Michalek and Berker Peksag
Diffstat (limited to 'Lib/lib2to3/fixer_util.py')
-rw-r--r--Lib/lib2to3/fixer_util.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/lib2to3/fixer_util.py b/Lib/lib2to3/fixer_util.py
index 60d219f..6e259c5 100644
--- a/Lib/lib2to3/fixer_util.py
+++ b/Lib/lib2to3/fixer_util.py
@@ -129,6 +129,29 @@ def FromImport(package_name, name_leafs):
imp = Node(syms.import_from, children)
return imp
+def ImportAndCall(node, results, names):
+ """Returns an import statement and calls a method
+ of the module:
+
+ import module
+ module.name()"""
+ obj = results["obj"].clone()
+ if obj.type == syms.arglist:
+ newarglist = obj.clone()
+ else:
+ newarglist = Node(syms.arglist, [obj.clone()])
+ after = results["after"]
+ if after:
+ after = [n.clone() for n in after]
+ new = Node(syms.power,
+ Attr(Name(names[0]), Name(names[1])) +
+ [Node(syms.trailer,
+ [results["lpar"].clone(),
+ newarglist,
+ results["rpar"].clone()])] + after)
+ new.prefix = node.prefix
+ return new
+
###########################################################
### Determine whether a node represents a given literal