@@ -499,39 +499,53 @@ def register_readline():
499
499
500
500
import atexit
501
501
try :
502
- import readline
503
- import rlcompleter # noqa: F401
502
+ try :
503
+ import readline
504
+ except ImportError :
505
+ readline = None
506
+ else :
507
+ import rlcompleter # noqa: F401
508
+ except ImportError :
509
+ return
510
+
511
+ try :
504
512
if PYTHON_BASIC_REPL :
505
513
CAN_USE_PYREPL = False
506
514
else :
507
515
original_path = sys .path
508
516
sys .path = [p for p in original_path if p != '' ]
509
517
try :
510
518
import _pyrepl .readline
511
- import _pyrepl .unix_console
519
+ if os .name == "nt" :
520
+ import _pyrepl .windows_console
521
+ console_errors = (_pyrepl .windows_console ._error ,)
522
+ else :
523
+ import _pyrepl .unix_console
524
+ console_errors = _pyrepl .unix_console ._error
512
525
from _pyrepl .main import CAN_USE_PYREPL
513
526
finally :
514
527
sys .path = original_path
515
528
except ImportError :
516
529
return
517
530
518
- # Reading the initialization (config) file may not be enough to set a
519
- # completion key, so we set one first and then read the file.
520
- if readline .backend == 'editline' :
521
- readline .parse_and_bind ('bind ^I rl_complete' )
522
- else :
523
- readline .parse_and_bind ('tab: complete' )
531
+ if readline is not None :
532
+ # Reading the initialization (config) file may not be enough to set a
533
+ # completion key, so we set one first and then read the file.
534
+ if readline .backend == 'editline' :
535
+ readline .parse_and_bind ('bind ^I rl_complete' )
536
+ else :
537
+ readline .parse_and_bind ('tab: complete' )
524
538
525
- try :
526
- readline .read_init_file ()
527
- except OSError :
528
- # An OSError here could have many causes, but the most likely one
529
- # is that there's no .inputrc file (or .editrc file in the case of
530
- # Mac OS X + libedit) in the expected location. In that case, we
531
- # want to ignore the exception.
532
- pass
539
+ try :
540
+ readline .read_init_file ()
541
+ except OSError :
542
+ # An OSError here could have many causes, but the most likely one
543
+ # is that there's no .inputrc file (or .editrc file in the case of
544
+ # Mac OS X + libedit) in the expected location. In that case, we
545
+ # want to ignore the exception.
546
+ pass
533
547
534
- if readline .get_current_history_length () == 0 :
548
+ if readline is None or readline .get_current_history_length () == 0 :
535
549
# If no history was loaded, default to .python_history,
536
550
# or PYTHON_HISTORY.
537
551
# The guard is necessary to avoid doubling history size at
@@ -542,8 +556,10 @@ def register_readline():
542
556
543
557
if CAN_USE_PYREPL :
544
558
readline_module = _pyrepl .readline
545
- exceptions = (OSError , * _pyrepl . unix_console . _error )
559
+ exceptions = (OSError , * console_errors )
546
560
else :
561
+ if readline is None :
562
+ return
547
563
readline_module = readline
548
564
exceptions = OSError
549
565
0 commit comments