(namespace: Mapping[str, Any])
| 591 | |
| 592 | |
| 593 | def _setup(namespace: Mapping[str, Any]) -> None: |
| 594 | global raw_input |
| 595 | if raw_input is not None: |
| 596 | return # don't run _setup twice |
| 597 | |
| 598 | try: |
| 599 | f_in = sys.stdin.fileno() |
| 600 | f_out = sys.stdout.fileno() |
| 601 | except (AttributeError, ValueError): |
| 602 | return |
| 603 | if not os.isatty(f_in) or not os.isatty(f_out): |
| 604 | return |
| 605 | |
| 606 | _wrapper.f_in = f_in |
| 607 | _wrapper.f_out = f_out |
| 608 | |
| 609 | # set up namespace in rlcompleter, which requires it to be a bona fide dict |
| 610 | if not isinstance(namespace, dict): |
| 611 | namespace = dict(namespace) |
| 612 | _wrapper.config.module_completer = ModuleCompleter(namespace) |
| 613 | use_basic_completer = ( |
| 614 | not sys.flags.ignore_environment |
| 615 | and os.getenv("PYTHON_BASIC_COMPLETER") |
| 616 | ) |
| 617 | completer_cls = RLCompleter if use_basic_completer else FancyCompleter |
| 618 | _wrapper.config.readline_completer = completer_cls(namespace).complete |
| 619 | |
| 620 | # this is not really what readline.c does. Better than nothing I guess |
| 621 | import builtins |
| 622 | raw_input = builtins.input |
| 623 | builtins.input = _wrapper.input |
| 624 | |
| 625 | |
| 626 | raw_input: Callable[[object], str] | None = None |
no test coverage detected
searching dependent graphs…