also changed the imports stuff to partially support compiled

This commit is contained in:
Dave Halter
2014-01-09 14:38:15 +01:00
parent 11e2446438
commit 7965cae373
2 changed files with 32 additions and 9 deletions

View File

@@ -3,11 +3,13 @@ Imitate the parser representation.
""" """
import inspect import inspect
import re import re
import sys
from jedi._compatibility import builtins as _builtins, is_py3k from jedi._compatibility import builtins as _builtins, is_py3k, exec_function
from jedi import debug from jedi import debug
from jedi.parser.representation import Base from jedi.parser.representation import Base
from jedi.cache import underscore_memoization from jedi.cache import underscore_memoization
from jedi.evaluate.sys_path import get_sys_path
# TODO # TODO
@@ -22,7 +24,7 @@ class PyObject(Base):
self.doc = inspect.getdoc(obj) self.doc = inspect.getdoc(obj)
# comply with the parser # comply with the parser
self.get_parent_until = lambda: parent self.get_parent_until = lambda *args, **kwargs: parent
self.start_pos = 0, 0 self.start_pos = 0, 0
def __repr__(self): def __repr__(self):
@@ -72,8 +74,10 @@ class PyObject(Base):
pass pass
def get_self_attributes(self): def get_self_attributes(self):
# Instance compatibility return [] # Instance compatibility
return []
def get_imports(self):
return [] # Builtins don't have imports
class PyName(object): class PyName(object):
@@ -105,6 +109,25 @@ class PyName(object):
return self._name return self._name
def load_module(path, name):
sys_path = get_sys_path()
if path:
sys_path.insert(0, path)
temp, sys.path = sys.path, sys_path
content = {}
try:
exec_function('import %s as module' % name, content)
module = content['module']
except AttributeError:
# use sys.modules, because you cannot access some modules
# directly. -> github issue #59
module = sys.modules[name]
sys.path = temp
return PyObject(module)
docstr_defaults = { docstr_defaults = {
'floating point number': 'float', 'floating point number': 'float',
'character': 'str', 'character': 'str',

View File

@@ -25,6 +25,7 @@ from jedi.parser import representation as pr
from jedi.evaluate import sys_path from jedi.evaluate import sys_path
from jedi import settings from jedi import settings
from jedi.common import source_to_unicode from jedi.common import source_to_unicode
from jedi.evaluate import compiled
class ModuleNotFound(Exception): class ModuleNotFound(Exception):
@@ -381,8 +382,9 @@ def strip_imports(evaluator, scopes):
@cache.cache_star_import @cache.cache_star_import
def remove_star_imports(evaluator, scope, ignored_modules=()): def remove_star_imports(evaluator, scope, ignored_modules=()):
""" """
Check a module for star imports: Check a module for star imports::
>>> from module import *
from module import *
and follow these modules. and follow these modules.
""" """
@@ -404,9 +406,7 @@ def load_module(path=None, source=None, name=None):
with open(path) as f: with open(path) as f:
source = f.read() source = f.read()
else: else:
# TODO refactoring remove return compiled.load_module(path, name)
from jedi.evaluate import builtin
return builtin.BuiltinModule(path, name).parser.module
p = path or name p = path or name
p = fast.FastParser(common.source_to_unicode(source), p) p = fast.FastParser(common.source_to_unicode(source), p)
cache.save_parser(path, name, p) cache.save_parser(path, name, p)