mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-16 10:37:52 +08:00
also changed the imports stuff to partially support compiled
This commit is contained in:
@@ -3,11 +3,13 @@ Imitate the parser representation.
|
||||
"""
|
||||
import inspect
|
||||
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.parser.representation import Base
|
||||
from jedi.cache import underscore_memoization
|
||||
from jedi.evaluate.sys_path import get_sys_path
|
||||
|
||||
|
||||
# TODO
|
||||
@@ -22,7 +24,7 @@ class PyObject(Base):
|
||||
self.doc = inspect.getdoc(obj)
|
||||
|
||||
# comply with the parser
|
||||
self.get_parent_until = lambda: parent
|
||||
self.get_parent_until = lambda *args, **kwargs: parent
|
||||
self.start_pos = 0, 0
|
||||
|
||||
def __repr__(self):
|
||||
@@ -72,8 +74,10 @@ class PyObject(Base):
|
||||
pass
|
||||
|
||||
def get_self_attributes(self):
|
||||
# Instance compatibility
|
||||
return []
|
||||
return [] # Instance compatibility
|
||||
|
||||
def get_imports(self):
|
||||
return [] # Builtins don't have imports
|
||||
|
||||
|
||||
class PyName(object):
|
||||
@@ -105,6 +109,25 @@ class PyName(object):
|
||||
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 = {
|
||||
'floating point number': 'float',
|
||||
'character': 'str',
|
||||
|
||||
@@ -25,6 +25,7 @@ from jedi.parser import representation as pr
|
||||
from jedi.evaluate import sys_path
|
||||
from jedi import settings
|
||||
from jedi.common import source_to_unicode
|
||||
from jedi.evaluate import compiled
|
||||
|
||||
|
||||
class ModuleNotFound(Exception):
|
||||
@@ -381,8 +382,9 @@ def strip_imports(evaluator, scopes):
|
||||
@cache.cache_star_import
|
||||
def remove_star_imports(evaluator, scope, ignored_modules=()):
|
||||
"""
|
||||
Check a module for star imports:
|
||||
>>> from module import *
|
||||
Check a module for star imports::
|
||||
|
||||
from module import *
|
||||
|
||||
and follow these modules.
|
||||
"""
|
||||
@@ -404,9 +406,7 @@ def load_module(path=None, source=None, name=None):
|
||||
with open(path) as f:
|
||||
source = f.read()
|
||||
else:
|
||||
# TODO refactoring remove
|
||||
from jedi.evaluate import builtin
|
||||
return builtin.BuiltinModule(path, name).parser.module
|
||||
return compiled.load_module(path, name)
|
||||
p = path or name
|
||||
p = fast.FastParser(common.source_to_unicode(source), p)
|
||||
cache.save_parser(path, name, p)
|
||||
|
||||
Reference in New Issue
Block a user