1
0
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:
Dave Halter
2015-04-08 02:41:59 +02:00
parent 9149c5adc2
commit 474d390220
3 changed files with 26 additions and 4 deletions

View File

@@ -11,6 +11,7 @@ correct implementation is delegated to _compatibility.
This module also supports import autocompletion, which means to complete This module also supports import autocompletion, which means to complete
statements like ``from datetim`` (curser at the end would return ``datetime``). statements like ``from datetim`` (curser at the end would return ``datetime``).
""" """
import imp
import os import os
import pkgutil import pkgutil
import sys import sys
@@ -378,9 +379,14 @@ class _Importer(object):
if is_package_directory or current_namespace[0]: if is_package_directory or current_namespace[0]:
# is a directory module # is a directory module
if is_package_directory: if is_package_directory:
path = os.path.join(path, '__init__.py') for suffix, _, _ in imp.get_suffixes():
with open(path, 'rb') as f: p = os.path.join(path, '__init__' + suffix)
source = f.read() 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: else:
source = current_namespace[0].read() source = current_namespace[0].read()
current_namespace[0].close() current_namespace[0].close()

View File

@@ -2,7 +2,7 @@
addopts = --doctest-modules addopts = --doctest-modules
# Ignore broken files in blackbox test directories # 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 # 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 # fine as long as we are using `clean_jedi_cache` as a session scoped

View File

@@ -4,6 +4,7 @@ Test compiled module
import os import os
import jedi import jedi
from ..helpers import cwd_at
def test_completions(): def test_completions():
@@ -29,3 +30,18 @@ def test_call_signatures_stdlib():
sigs = s.call_signatures() sigs = s.call_signatures()
assert len(sigs) == 1 assert len(sigs) == 1
assert len(sigs[0].params) == 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()]