1313
1414
1515from functools import reduce , partial
16- from itertools import ifilter , ifilterfalse , izip , tee
16+ from itertools import filterfalse , tee
1717from logging import debug , warn
1818from re import compile as recompile , sub as resub
1919
@@ -31,7 +31,7 @@ def __init__(self):
3131class Base (object ):
3232 """ Base -> Parent class for AST visitors. """
3333
34- commentSubs = map (recompile , ['^\s*/(\*)+' , '(\*)+/\s*$' , '^\s*//' ])
34+ commentSubs = list ( map (recompile , ['^\s*/(\*)+' , '(\*)+/\s*$' , '^\s*//' ]) )
3535
3636 def accept (self , node , memo ):
3737 """ Accept a node, possibly creating a child visitor. """
@@ -48,7 +48,7 @@ def insertComments(self, tmpl, tree, index, memo):
4848 cache , parser , comTypes = memo .comments , tree .parser , tokens .commentTypes
4949 comNew = lambda t :t .type in comTypes and (t .index not in cache )
5050
51- for tok in ifilter (comNew , parser .input .tokens [memo .last :index ]):
51+ for tok in filter (comNew , parser .input .tokens [memo .last :index ]):
5252 cache .add (tok .index )
5353
5454 # loop over parents until we find the top expression
@@ -70,7 +70,7 @@ def insertComments(self, tmpl, tree, index, memo):
7070 def stripComment (self , text ):
7171 """ Regex substitutions for comments; removes comment characters. """
7272 subText = lambda value , regex :resub (regex , '' , value )
73- for text in ifilter ( unicode .strip , text .split ('\n ' )):
73+ for text in filter ( str .strip , text .split ('\n ' )):
7474 yield reduce (subText , self .commentSubs , text )
7575
7676 def walk (self , tree , memo = None ):
@@ -95,7 +95,7 @@ def walk(self, tree, memo=None):
9595
9696 def zipWalk (self , nodes , visitors , memo ):
9797 """ Walk the given nodes zipped with the given visitors. """
98- for node , visitor in izip (nodes , visitors ):
98+ for node , visitor in zip (nodes , visitors ):
9999 visitor .walk (node , memo )
100100
101101 def nodeTypeToString (self , node ):
@@ -132,7 +132,7 @@ def acceptType(self, node, memo):
132132 _acceptInterface = makeAcceptType ('interface' )
133133
134134 def acceptInterface (self , node , memo ):
135- module = self .parents (lambda x :x .isModule ). next ( )
135+ module = next ( self .parents (lambda x :x .isModule ))
136136 module .needsAbstractHelpers = True
137137 return self ._acceptInterface (node , memo )
138138
@@ -161,9 +161,9 @@ class ModifiersAcceptor(object):
161161 def acceptModifierList (self , node , memo ):
162162 """ Accept and process class and method modifiers. """
163163 isAnno = lambda token :token .type == tokens .AT
164- for ano in ifilter (isAnno , node .children ):
164+ for ano in filter (isAnno , node .children ):
165165 self .nodesToAnnos (ano , memo )
166- for mod in ifilterfalse (isAnno , node .children ):
166+ for mod in filterfalse (isAnno , node .children ):
167167 self .nodesToModifiers (mod , node )
168168 return self
169169
@@ -407,7 +407,7 @@ def acceptCatch(self, node, memo):
407407
408408 def acceptContinue (self , node , memo ):
409409 """ Accept and process a continue statement. """
410- parent = node .parents (lambda x : x .type in {tokens .FOR , tokens .FOR_EACH , tokens .DO , tokens .WHILE }). next ( )
410+ parent = next ( node .parents (lambda x : x .type in {tokens .FOR , tokens .FOR_EACH , tokens .DO , tokens .WHILE }))
411411 if parent .type == tokens .FOR :
412412 updateStat = self .factory .expr (parent = self )
413413 updateStat .walk (parent .firstChildOfType (tokens .FOR_UPDATE ), memo )
@@ -561,7 +561,7 @@ def acceptSwitch(self, node, memo):
561561
562562 def acceptSynchronized (self , node , memo ):
563563 """ Accept and process a synchronized statement (not a modifier). """
564- module = self .parents (lambda x :x .isModule ). next ( )
564+ module = next ( self .parents (lambda x :x .isModule ))
565565 module .needsSyncHelpers = True
566566 if node .parent .type == tokens .MODIFIER_LIST :
567567 # Skip any synchronized modifier
@@ -743,7 +743,7 @@ def acceptPrePost(self, node, memo):
743743 name = node .firstChildOfType (tokens .IDENT ).text
744744 handler = self .configHandler ('VariableNaming' )
745745 rename = handler (name )
746- block = self .parents (lambda x :x .isMethod ). next ( )
746+ block = next ( self .parents (lambda x :x .isMethod ))
747747 if pre :
748748 left = name
749749 else :
@@ -768,7 +768,7 @@ def acceptBitShiftRight(self, node, memo):
768768 self .fs = 'bsr(' + FS .l + ', ' + FS .r + ')'
769769 self .left , self .right = visitors = factory (parent = self ), factory ()
770770 self .zipWalk (node .children , visitors , memo )
771- module = self .parents (lambda x :x .isModule ). next ( )
771+ module = next ( self .parents (lambda x :x .isModule ))
772772 module .needsBsrFunc = True
773773
774774 def acceptBitShiftRightAssign (self , node , memo ):
@@ -777,7 +777,7 @@ def acceptBitShiftRightAssign(self, node, memo):
777777 self .fs = FS .l + ' = bsr(' + FS .l + ', ' + FS .r + ')'
778778 self .left , self .right = visitors = factory (parent = self ), factory ()
779779 self .zipWalk (node .children , visitors , memo )
780- module = self .parents (lambda x :x .isModule ). next ( )
780+ module = next ( self .parents (lambda x :x .isModule ))
781781 module .needsBsrFunc = True
782782
783783 def acceptClassConstructorCall (self , node , memo ):
@@ -853,12 +853,12 @@ def acceptStaticArrayCreator(self, node, memo):
853853
854854 def acceptSuper (self , node , memo ):
855855 """ Accept and process a super expression. """
856- cls = self .parents (lambda c :c .isClass ). next ( )
856+ cls = next ( self .parents (lambda c :c .isClass ))
857857 self .right = self .factory .expr (fs = 'super({name}, self)' .format (name = cls .name ))
858858
859859 def acceptSuperConstructorCall (self , node , memo ):
860860 """ Accept and process a super constructor call. """
861- cls = self .parents (lambda c :c .isClass ). next ( )
861+ cls = next ( self .parents (lambda c :c .isClass ))
862862 fs = 'super(' + FS .l + ', self).__init__(' + FS .r + ')'
863863 self .right = self .factory .expr (fs = fs , left = cls .name )
864864 return self .right
0 commit comments