@@ -514,35 +514,52 @@ def displayhook(self, obj):
514
514
if obj is not None :
515
515
self .message (repr (obj ))
516
516
517
+ @contextmanager
518
+ def _disable_tab_completion (self ):
519
+ if self .use_rawinput and self .completekey == 'tab' :
520
+ try :
521
+ import readline
522
+ except ImportError :
523
+ yield
524
+ return
525
+ try :
526
+ readline .parse_and_bind ('tab: self-insert' )
527
+ yield
528
+ finally :
529
+ readline .parse_and_bind ('tab: complete' )
530
+ else :
531
+ yield
532
+
517
533
def default (self , line ):
518
534
if line [:1 ] == '!' : line = line [1 :].strip ()
519
535
locals = self .curframe_locals
520
536
globals = self .curframe .f_globals
521
537
try :
522
538
if (code := codeop .compile_command (line + '\n ' , '<stdin>' , 'single' )) is None :
523
539
# Multi-line mode
524
- buffer = line
525
- continue_prompt = "... "
526
- while (code := codeop .compile_command (buffer , '<stdin>' , 'single' )) is None :
527
- if self .use_rawinput :
528
- try :
529
- line = input (continue_prompt )
530
- except (EOFError , KeyboardInterrupt ):
531
- self .lastcmd = ""
532
- print ('\n ' )
533
- return
534
- else :
535
- self .stdout .write (continue_prompt )
536
- self .stdout .flush ()
537
- line = self .stdin .readline ()
538
- if not len (line ):
539
- self .lastcmd = ""
540
- self .stdout .write ('\n ' )
541
- self .stdout .flush ()
542
- return
540
+ with self ._disable_tab_completion ():
541
+ buffer = line
542
+ continue_prompt = "... "
543
+ while (code := codeop .compile_command (buffer , '<stdin>' , 'single' )) is None :
544
+ if self .use_rawinput :
545
+ try :
546
+ line = input (continue_prompt )
547
+ except (EOFError , KeyboardInterrupt ):
548
+ self .lastcmd = ""
549
+ print ('\n ' )
550
+ return
543
551
else :
544
- line = line .rstrip ('\r \n ' )
545
- buffer += '\n ' + line
552
+ self .stdout .write (continue_prompt )
553
+ self .stdout .flush ()
554
+ line = self .stdin .readline ()
555
+ if not len (line ):
556
+ self .lastcmd = ""
557
+ self .stdout .write ('\n ' )
558
+ self .stdout .flush ()
559
+ return
560
+ else :
561
+ line = line .rstrip ('\r \n ' )
562
+ buffer += '\n ' + line
546
563
save_stdout = sys .stdout
547
564
save_stdin = sys .stdin
548
565
save_displayhook = sys .displayhook
0 commit comments