Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Lib/rlcompleter.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import atexit
import builtins
import inspect
import keyword
import re
import __main__

__all__ = ["Completer"]
Expand Down Expand Up @@ -113,7 +115,6 @@ def global_matches(self, text):
defined in self.namespace that match.

"""
import keyword
matches = []
seen = {"__builtins__"}
n = len(text)
Expand Down Expand Up @@ -146,7 +147,6 @@ def attr_matches(self, text):
with a __getattr__ hook is evaluated.

"""
import re
m = re.match(r"(\w+(\.\w+)*)\.(\w*)", text)
if not m:
return []
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
``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.
11 changes: 10 additions & 1 deletion Modules/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ pymain_import_readline(const PyConfig *config)
else {
Py_DECREF(mod);
}
mod = PyImport_ImportModule("rlcompleter");
if (mod == NULL) {
PyErr_Clear();
}
else {
Py_DECREF(mod);
}
}


Expand Down Expand Up @@ -555,6 +562,9 @@ pymain_run_python(int *exitcode)
}
}

// 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;
Expand All @@ -577,7 +587,6 @@ pymain_run_python(int *exitcode)
}

pymain_header(config);
pymain_import_readline(config);

if (config->run_command) {
*exitcode = pymain_run_command(config->run_command);
Expand Down