Skip to content

Commit fb78692

Browse files
tstomit66
authored andcommitted
fixed undefined variable children_hooks + imports cleanup
1 parent 39a066e commit fb78692

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/libfuturize/fixer_util.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
"""
1010

1111
from lib2to3.fixer_util import (FromImport, Newline, is_import,
12-
find_root, does_tree_import, Comma)
12+
find_root, does_tree_import,
13+
Call, Name, Comma)
1314
from lib2to3.pytree import Leaf, Node
14-
from lib2to3.pygram import python_symbols as syms, python_grammar
15+
from lib2to3.pygram import python_symbols as syms
1516
from lib2to3.pygram import token
16-
from lib2to3.fixer_util import (Node, Call, Name, syms, Comma, Number)
1717
import re
1818

1919

@@ -62,7 +62,7 @@ def Minus(prefix=None):
6262

6363
def commatize(leafs):
6464
"""
65-
Accepts/turns: (Name, Name, ..., Name, Name)
65+
Accepts/turns: (Name, Name, ..., Name, Name)
6666
Returns/into: (Name, Comma, Name, Comma, ..., Name, Comma, Name)
6767
"""
6868
new_leafs = []
@@ -272,7 +272,7 @@ def future_import2(feature, node):
272272
An alternative to future_import() which might not work ...
273273
"""
274274
root = find_root(node)
275-
275+
276276
if does_tree_import(u"__future__", feature, node):
277277
return
278278

@@ -304,7 +304,7 @@ def parse_args(arglist, scheme):
304304
Parse a list of arguments into a dict
305305
"""
306306
arglist = [i for i in arglist if i.type != token.COMMA]
307-
307+
308308
ret_mapping = dict([(k, None) for k in scheme])
309309

310310
for i, arg in enumerate(arglist):
@@ -338,7 +338,7 @@ def touch_import_top(package, name_to_import, node):
338338
Based on lib2to3.fixer_util.touch_import()
339339
340340
Calling this multiple times adds the imports in reverse order.
341-
341+
342342
Also adds "standard_library.install_aliases()" after "from future import
343343
standard_library". This should probably be factored into another function.
344344
"""
@@ -390,6 +390,7 @@ def touch_import_top(package, name_to_import, node):
390390
break
391391
insert_pos = idx
392392

393+
children_hooks = []
393394
if package is None:
394395
import_ = Node(syms.import_name, [
395396
Leaf(token.NAME, u"import"),
@@ -413,9 +414,7 @@ def touch_import_top(package, name_to_import, node):
413414
]
414415
)
415416
children_hooks = [install_hooks, Newline()]
416-
else:
417-
children_hooks = []
418-
417+
419418
# FromImport(package, [Leaf(token.NAME, name_to_import, prefix=u" ")])
420419

421420
children_import = [import_, Newline()]
@@ -445,7 +444,6 @@ def check_future_import(node):
445444
return set()
446445
node = node.children[3]
447446
# now node is the import_as_name[s]
448-
# print(python_grammar.number2symbol[node.type]) # breaks sometimes
449447
if node.type == syms.import_as_names:
450448
result = set()
451449
for n in node.children:

0 commit comments

Comments
 (0)