4343)
4444
4545if "c" in globals ():
46- del c
46+ del c # noqa: F821
4747
4848ISEARCH_DIRECTION_NONE = ""
4949ISEARCH_DIRECTION_BACKWARDS = "r"
@@ -71,11 +71,10 @@ def do(self):
7171class restore_history (commands .Command ):
7272 def do (self ):
7373 r = self .reader
74- if r .historyi != len (r .history ):
75- if r .get_unicode () != r .history [r .historyi ]:
76- r .buffer = list (r .history [r .historyi ])
77- r .pos = len (r .buffer )
78- r .dirty = 1
74+ if r .historyi != len (r .history ) and r .get_unicode () != r .history [r .historyi ]:
75+ r .buffer = list (r .history [r .historyi ])
76+ r .pos = len (r .buffer )
77+ r .dirty = 1
7978
8079
8180class first_history (commands .Command ):
@@ -111,10 +110,7 @@ def do(self):
111110 return
112111 w = words [a ]
113112 b = r .buffer
114- if r .yank_arg_i > 0 :
115- o = len (r .yank_arg_yanked )
116- else :
117- o = 0
113+ o = len (r .yank_arg_yanked ) if r .yank_arg_i > 0 else 0
118114 b [r .pos - o : r .pos ] = list (w )
119115 r .yank_arg_yanked = w
120116 r .pos += len (w ) - o
@@ -212,7 +208,7 @@ class HistoricalReader(R):
212208 """
213209
214210 def collect_keymap (self ):
215- return super (HistoricalReader , self ).collect_keymap () + (
211+ return super ().collect_keymap () + (
216212 (r"\C-n" , "next-history" ),
217213 (r"\C-p" , "previous-history" ),
218214 (r"\C-o" , "operate-and-get-next" ),
@@ -225,7 +221,7 @@ def collect_keymap(self):
225221 )
226222
227223 def __init__ (self , console ):
228- super (HistoricalReader , self ).__init__ (console )
224+ super ().__init__ (console )
229225 self .history = []
230226 self .historyi = 0
231227 self .transient_history = {}
@@ -274,7 +270,7 @@ def get_item(self, i):
274270 return self .transient_history .get (i , self .get_unicode ())
275271
276272 def prepare (self ):
277- super (HistoricalReader , self ).prepare ()
273+ super ().prepare ()
278274 try :
279275 self .transient_history = {}
280276 if self .next_history is not None and self .next_history < len (self .history ):
@@ -292,9 +288,9 @@ def prepare(self):
292288 def get_prompt (self , lineno , cursor_on_line ):
293289 if cursor_on_line and self .isearch_direction != ISEARCH_DIRECTION_NONE :
294290 d = "rf" [self .isearch_direction == ISEARCH_DIRECTION_FORWARDS ]
295- return "(%s -search `%s') " % ( d , self .isearch_term )
291+ return f"( { d } -search `{ self .isearch_term } ') "
296292 else :
297- return super (HistoricalReader , self ).get_prompt (lineno , cursor_on_line )
293+ return super ().get_prompt (lineno , cursor_on_line )
298294
299295 def isearch_next (self ):
300296 st = self .isearch_term
@@ -303,10 +299,7 @@ def isearch_next(self):
303299 s = self .get_unicode ()
304300 forwards = self .isearch_direction == ISEARCH_DIRECTION_FORWARDS
305301 while 1 :
306- if forwards :
307- p = s .find (st , p + 1 )
308- else :
309- p = s .rfind (st , 0 , p + len (st ) - 1 )
302+ p = s .find (st , p + 1 ) if forwards else s .rfind (st , 0 , p + len (st ) - 1 )
310303 if p != - 1 :
311304 self .select_item (i )
312305 self .pos = p
@@ -325,7 +318,7 @@ def isearch_next(self):
325318 p = len (s )
326319
327320 def finish (self ):
328- super (HistoricalReader , self ).finish ()
321+ super ().finish ()
329322 ret = self .get_unicode ()
330323 for i , t in list (self .transient_history .items ()):
331324 if i < len (self .history ) and i != self .historyi :
0 commit comments