Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b62d051

Browse files
committed
Don't fail when completing modules ending with dot.
Mitigate #10170 don't considered as a fix as it does not populate the completion, just prevent crash.
1 parent d6ec616 commit b62d051

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

IPython/core/completerlib.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,12 @@ def is_importable(module, attr, only_modules):
152152
else:
153153
return not(attr[:2] == '__' and attr[-2:] == '__')
154154

155-
def try_import(mod, only_modules=False):
155+
156+
def try_import(mod: str, only_modules=False):
157+
"""
158+
Try to import given module and return list of potential completions.
159+
"""
160+
mod = mod.rstrip('.')
156161
try:
157162
m = import_module(mod)
158163
except:

IPython/core/tests/test_completer.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,14 @@ def test_object_key_completion():
712712
nt.assert_in('qwick', matches)
713713

714714

715+
def test_tryimport():
716+
"""
717+
Test that try-import don't crash on trailing dot, and import modules before
718+
"""
719+
from IPython.core.completerlib import try_import
720+
assert(try_import("IPython."))
721+
722+
715723
def test_aimport_module_completer():
716724
ip = get_ipython()
717725
_, matches = ip.complete('i', '%aimport i')

0 commit comments

Comments
 (0)