2020"""
2121
2222# Local imports
23- from .. import pytree
24- from .. import patcomp
2523from ..pgen2 import token
2624from . import basefix
27- from .util import Name , Call , ListComp , attr_chain , does_tree_import
25+ from .util import Name , Call , ListComp , does_tree_import , in_special_context
2826from ..pygram import python_symbols as syms
2927
3028class FixMap (basefix .BaseFix ):
@@ -71,7 +69,7 @@ def transform(self, node, results):
7169 # If a future map has been imported for this file, we won't
7270 # be making any modifications
7371 return
74-
72+
7573 if node .parent .type == syms .simple_stmt :
7674 self .warning (node , "You should use a for loop here" )
7775 new = node .clone ()
@@ -92,35 +90,3 @@ def transform(self, node, results):
9290 new = Call (Name ("list" ), [new ])
9391 new .set_prefix (node .get_prefix ())
9492 return new
95-
96- P0 = """for_stmt< 'for' any 'in' node=any ':' any* >
97- | comp_for< 'for' any 'in' node=any any* >
98- """
99- p0 = patcomp .compile_pattern (P0 )
100-
101- P1 = """
102- power<
103- ( 'iter' | 'list' | 'tuple' | 'sorted' | 'set' | 'sum' |
104- 'any' | 'all' | (any* trailer< '.' 'join' >) )
105- trailer< '(' node=any ')' >
106- any*
107- >
108- """
109- p1 = patcomp .compile_pattern (P1 )
110-
111- P2 = """
112- power<
113- 'sorted'
114- trailer< '(' arglist<node=any any*> ')' >
115- any*
116- >
117- """
118- p2 = patcomp .compile_pattern (P2 )
119-
120- def in_special_context (node ):
121- patterns = [p0 , p1 , p2 ]
122- for pattern , parent in zip (patterns , attr_chain (node , "parent" )):
123- results = {}
124- if pattern .match (parent , results ) and results ["node" ] is node :
125- return True
126- return False
0 commit comments