@@ -117,19 +117,17 @@ def visit(
117
117
settings : Settings ,
118
118
filename : str ,
119
119
) -> dict [Offset , list [TokenFunc ]]:
120
- initial_state = State (
120
+ state = State (
121
121
settings = settings ,
122
122
filename = filename ,
123
123
from_imports = defaultdict (set ),
124
124
)
125
- ast_funcs = get_ast_funcs (initial_state , settings )
125
+ ast_funcs = get_ast_funcs (state , settings )
126
126
127
- nodes : list [tuple [State , ast .AST , tuple [ast .AST , ...]]] = [
128
- (initial_state , tree , ())
129
- ]
127
+ nodes : list [tuple [ast .AST , tuple [ast .AST , ...]]] = [(tree , ())]
130
128
ret = defaultdict (list )
131
129
while nodes :
132
- state , node , parents = nodes .pop ()
130
+ node , parents = nodes .pop ()
133
131
134
132
for ast_func in ast_funcs [type (node )]:
135
133
for offset , token_func in ast_func (state , node , parents ):
@@ -152,14 +150,13 @@ def visit(
152
150
subparents = parents + (node ,)
153
151
for name in reversed (node ._fields ):
154
152
value = getattr (node , name )
155
- next_state = state
156
153
157
154
if isinstance (value , ast .AST ):
158
- nodes .append ((next_state , value , subparents ))
155
+ nodes .append ((value , subparents ))
159
156
elif isinstance (value , list ):
160
157
for subvalue in reversed (value ):
161
158
if isinstance (subvalue , ast .AST ):
162
- nodes .append ((next_state , subvalue , subparents ))
159
+ nodes .append ((subvalue , subparents ))
163
160
return ret
164
161
165
162
0 commit comments