diff --git a/IPython/core/completerlib.py b/IPython/core/completerlib.py index 466041f..4a30980 100644 --- a/IPython/core/completerlib.py +++ b/IPython/core/completerlib.py @@ -80,10 +80,15 @@ def module_list(path): pjoin = os.path.join basename = os.path.basename + def is_importable_file(path): + """Returns True if the provided path is a valid importable module""" + name, extension = os.path.splitext( path ) + return import_re.match(path) and py3compat.isidentifier(name) + # Now find actual path matches for packages or modules folder_list = [p for p in folder_list if isfile(pjoin(path, p,'__init__.py')) - or import_re.match(p) ] + or is_importable_file(p) ] return [basename(p).split('.')[0] for p in folder_list] diff --git a/IPython/core/tests/test_completerlib.py b/IPython/core/tests/test_completerlib.py index b442eb9..745f838 100644 --- a/IPython/core/tests/test_completerlib.py +++ b/IPython/core/tests/test_completerlib.py @@ -76,4 +76,5 @@ class Test_magic_run_completer(unittest.TestCase): open(filename, 'w').close() s = set( module_completion('import foo') ) - self.assertFalse( s.intersection(invalid_module_names) ) + intersection = s.intersection(invalid_module_names) + self.assertFalse(intersection, intersection)