Configure readline completion on interactive prompts. If the readline module can be imported, the hook will set the Tab key as completion key and register ~/.python_history as history file. This can be overridden in the sitecustomize or usercustomize module, or in a PYTHONSTARTUP fi
()
| 490 | |
| 491 | |
| 492 | def register_readline(): |
| 493 | """Configure readline completion on interactive prompts. |
| 494 | |
| 495 | If the readline module can be imported, the hook will set the Tab key |
| 496 | as completion key and register ~/.python_history as history file. |
| 497 | This can be overridden in the sitecustomize or usercustomize module, |
| 498 | or in a PYTHONSTARTUP file. |
| 499 | """ |
| 500 | if not sys.flags.ignore_environment: |
| 501 | PYTHON_BASIC_REPL = os.getenv("PYTHON_BASIC_REPL") |
| 502 | else: |
| 503 | PYTHON_BASIC_REPL = False |
| 504 | |
| 505 | import atexit |
| 506 | |
| 507 | try: |
| 508 | try: |
| 509 | import readline |
| 510 | except ImportError: |
| 511 | readline = None |
| 512 | else: |
| 513 | import rlcompleter # noqa: F401 |
| 514 | except ImportError: |
| 515 | return |
| 516 | |
| 517 | try: |
| 518 | if PYTHON_BASIC_REPL: |
| 519 | CAN_USE_PYREPL = False |
| 520 | else: |
| 521 | original_path = sys.path |
| 522 | sys.path = [p for p in original_path if p != ''] |
| 523 | try: |
| 524 | import _pyrepl.readline |
| 525 | if os.name == "nt": |
| 526 | import _pyrepl.windows_console |
| 527 | console_errors = (_pyrepl.windows_console._error,) |
| 528 | else: |
| 529 | import _pyrepl.unix_console |
| 530 | console_errors = _pyrepl.unix_console._error |
| 531 | from _pyrepl.main import CAN_USE_PYREPL |
| 532 | except ModuleNotFoundError: |
| 533 | CAN_USE_PYREPL = False |
| 534 | finally: |
| 535 | sys.path = original_path |
| 536 | except ImportError: |
| 537 | return |
| 538 | |
| 539 | if readline is not None: |
| 540 | # Reading the initialization (config) file may not be enough to set a |
| 541 | # completion key, so we set one first and then read the file. |
| 542 | if readline.backend == 'editline': |
| 543 | readline.parse_and_bind('bind ^I rl_complete') |
| 544 | else: |
| 545 | readline.parse_and_bind('tab: complete') |
| 546 | |
| 547 | try: |
| 548 | readline.read_init_file() |
| 549 | except OSError: |
nothing calls this directly
no test coverage detected
searching dependent graphs…