forked from VimPlug/jedi
Use imp.get_suffixes to deal with __init__ files that are not .py files but .so etc. fixes #472
This commit is contained in:
@@ -11,6 +11,7 @@ correct implementation is delegated to _compatibility.
|
||||
This module also supports import autocompletion, which means to complete
|
||||
statements like ``from datetim`` (curser at the end would return ``datetime``).
|
||||
"""
|
||||
import imp
|
||||
import os
|
||||
import pkgutil
|
||||
import sys
|
||||
@@ -378,9 +379,14 @@ class _Importer(object):
|
||||
if is_package_directory or current_namespace[0]:
|
||||
# is a directory module
|
||||
if is_package_directory:
|
||||
path = os.path.join(path, '__init__.py')
|
||||
with open(path, 'rb') as f:
|
||||
source = f.read()
|
||||
for suffix, _, _ in imp.get_suffixes():
|
||||
p = os.path.join(path, '__init__' + suffix)
|
||||
if os.path.exists(p):
|
||||
if suffix == '.py':
|
||||
with open(path, 'rb') as f:
|
||||
source = f.read()
|
||||
else: # It's a binary!
|
||||
source = None
|
||||
else:
|
||||
source = current_namespace[0].read()
|
||||
current_namespace[0].close()
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
addopts = --doctest-modules
|
||||
|
||||
# Ignore broken files in blackbox test directories
|
||||
norecursedirs = .* docs completion refactor absolute_import namespace_package scripts extensions speed static_analysis not_in_sys_path buildout_project egg-link
|
||||
norecursedirs = .* docs completion refactor absolute_import namespace_package scripts extensions speed static_analysis not_in_sys_path buildout_project egg-link init_extension_module
|
||||
|
||||
# Activate `clean_jedi_cache` fixture for all tests. This should be
|
||||
# fine as long as we are using `clean_jedi_cache` as a session scoped
|
||||
|
||||
@@ -4,6 +4,7 @@ Test compiled module
|
||||
import os
|
||||
|
||||
import jedi
|
||||
from ..helpers import cwd_at
|
||||
|
||||
|
||||
def test_completions():
|
||||
@@ -29,3 +30,18 @@ def test_call_signatures_stdlib():
|
||||
sigs = s.call_signatures()
|
||||
assert len(sigs) == 1
|
||||
assert len(sigs[0].params) == 1
|
||||
|
||||
|
||||
@cwd_at('test/test_evaluate')
|
||||
def test_init_extension_module():
|
||||
"""
|
||||
``__init__`` extension modules are also packages and Jedi should understand
|
||||
that.
|
||||
|
||||
Originally coming from #472.
|
||||
"""
|
||||
s = jedi.Script('import init_extension_module as i\ni.', path='not_existing.py')
|
||||
assert 'foo' in [c.name for c in s.completions()]
|
||||
|
||||
s = jedi.Script('from init_extension_module import foo\nfoo', path='not_existing.py')
|
||||
assert ['foo'] == [c.name for c in s.completions()]
|
||||
|
||||
Reference in New Issue
Block a user