``pymain_run_python()`` now imports ``readline`` and ``rlcompleter``
before sys.path is extended to include the current working directory of
an interactive interpreter. Non-interactive interpreters are not
affected.
Also move imports of ``re`` and ``keyword`` module to top level so they
are materialized early, too. The ``keyword`` module is trivial and the
``re`` is already imported via ``inspect`` -> ``linecache``.
import atexit
import builtins
import inspect
+import keyword
+import re
import __main__
__all__ = ["Completer"]
defined in self.namespace that match.
"""
- import keyword
matches = []
seen = {"__builtins__"}
n = len(text)
with a __getattr__ hook is evaluated.
"""
- import re
m = re.match(r"(\w+(\.\w+)*)\.(\w*)", text)
if not m:
return []
--- /dev/null
+``pymain_run_python()`` now imports ``readline`` and ``rlcompleter`` before
+sys.path is extended to include the current working directory of an
+interactive interpreter. Non-interactive interpreters are not affected.
else {
Py_DECREF(mod);
}
+ mod = PyImport_ImportModule("rlcompleter");
+ if (mod == NULL) {
+ PyErr_Clear();
+ }
+ else {
+ Py_DECREF(mod);
+ }
}
}
}
+ // import readline and rlcompleter before script dir is added to sys.path
+ pymain_import_readline(config);
+
if (main_importer_path != NULL) {
if (pymain_sys_path_add_path0(interp, main_importer_path) < 0) {
goto error;
}
pymain_header(config);
- pymain_import_readline(config);
if (config->run_command) {
*exitcode = pymain_run_command(config->run_command);