aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el17
1 files changed, 11 insertions, 6 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 4c27136f3b5..48d80b99c6a 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -2653,25 +2653,30 @@ This function takes the list of setup code to send from the
2653 2653
2654(defcustom python-shell-completion-setup-code 2654(defcustom python-shell-completion-setup-code
2655 "try: 2655 "try:
2656 import readline, rlcompleter 2656 import __builtin__
2657except ImportError: 2657except ImportError:
2658 # Python 3
2659 import builtins as __builtin__
2660try:
2661 import readline, rlcompleter
2662except:
2658 def __PYTHON_EL_get_completions(text): 2663 def __PYTHON_EL_get_completions(text):
2659 return [] 2664 return []
2660else: 2665else:
2661 def __PYTHON_EL_get_completions(text): 2666 def __PYTHON_EL_get_completions(text):
2667 builtins = dir(__builtin__)
2662 completions = [] 2668 completions = []
2663 try: 2669 try:
2664 splits = text.split() 2670 splits = text.split()
2665 is_module = splits and splits[0] in ('from', 'import') 2671 is_module = splits and splits[0] in ('from', 'import')
2666 is_ipython = getattr( 2672 is_ipython = ('__IPYTHON__' in builtins or
2667 __builtins__, '__IPYTHON__', 2673 '__IPYTHON__active' in builtins)
2668 getattr(__builtins__, '__IPYTHON__active', False))
2669 if is_module: 2674 if is_module:
2670 from IPython.core.completerlib import module_completion 2675 from IPython.core.completerlib import module_completion
2671 completions = module_completion(text.strip()) 2676 completions = module_completion(text.strip())
2672 elif is_ipython and getattr(__builtins__, '__IP', None): 2677 elif is_ipython and '__IP' in builtins:
2673 completions = __IP.complete(text) 2678 completions = __IP.complete(text)
2674 elif is_ipython and getattr(__builtins__, 'get_ipython', None): 2679 elif is_ipython and 'get_ipython' in builtins:
2675 completions = get_ipython().Completer.all_completions(text) 2680 completions = get_ipython().Completer.all_completions(text)
2676 else: 2681 else:
2677 i = 0 2682 i = 0