1717__all__ = [
1818 "BaseAction" ,
1919 "InsertAfter" ,
20+ "InsertBefore" ,
2021 "LazyInsertAfter" ,
22+ "LazyInsertBefore" ,
2123 "LazyReplace" ,
2224 "Replace" ,
2325 "Erase" ,
@@ -195,7 +197,6 @@ def _stack_effect(self) -> tuple[ast.AST, int]:
195197 return (self .node , 1 )
196198
197199
198- @_hint ("deprecated_alias" , "NewStatementAction" )
199200@dataclass
200201class LazyInsertBefore (_LazyActionMixin [ast .stmt , ast .stmt ]):
201202 """Inserts the re-synthesized version :py:meth:`LazyInsertBefore.build`'s
@@ -217,25 +218,18 @@ def apply(self, context: Context, source: str) -> str:
217218
218219 replacement = split_lines (context .unparse (self .build ()))
219220 replacement .apply_indentation (indentation , start_prefix = start_prefix )
221+ replacement [- 1 ] += lines ._newline_type
220222
221223 original_node_start = cast (int , self .node .lineno )
222- if lines [original_node_start ].endswith (lines ._newline_type ):
223- replacement [- 1 ] += lines ._newline_type
224- else :
225- # If the original anchor's last line doesn't end with a newline,
226- # then we need to also prevent our new source from ending with
227- # a newline.
228- replacement [0 ] = lines ._newline_type + replacement [0 ]
229-
230224 for line in reversed (replacement ):
231225 lines .insert (original_node_start - 1 , line )
232226
233227 return lines .join ()
234228
235229 def _stack_effect (self ) -> tuple [ast .AST , int ]:
236- # Adding a statement right after the node will need to be reflected
230+ # Adding a statement right before the node will need to be reflected
237231 # in the block.
238- return (self .node , 1 )
232+ return (self .node , - 1 )
239233
240234
241235@dataclass
@@ -264,7 +258,6 @@ def build(self) -> ast.stmt:
264258 return self .target
265259
266260
267- @_hint ("deprecated_alias" , "TargetedNewStatementBeforeAction" )
268261@dataclass
269262class InsertBefore (LazyInsertBefore ):
270263 """Inserts the re-synthesized version of given `target` right after
@@ -341,7 +334,7 @@ def _resynthesize(self, context: Context) -> str:
341334 return ""
342335
343336 def _stack_effect (self ) -> tuple [ast .AST , int ]:
344- # Erasing a single node mean positions of all the followinng statements will
337+ # Erasing a single node mean positions of all the following statements will
345338 # need to reduced by 1.
346339 return (self .node , - 1 )
347340
0 commit comments