make first faked compiled modules work

This commit is contained in:
Dave Halter
2014-01-10 23:35:53 +01:00
parent 78cc015b9d
commit 01c03966a7
3 changed files with 11 additions and 4 deletions

View File

@@ -74,7 +74,7 @@ class PyObject(Base):
elif t == 'def': elif t == 'def':
for name in self._parse_function_doc()[1].split(): for name in self._parse_function_doc()[1].split():
try: try:
yield PyObject(getattr(_builtins, name), builtin, True) yield create(getattr(_builtins, name), builtin, True)
except AttributeError: except AttributeError:
pass pass
@@ -99,7 +99,7 @@ class PyName(object):
def parent(self): def parent(self):
try: try:
# this has a builtin_function_or_method # this has a builtin_function_or_method
return PyObject(getattr(self._obj.obj, self._name), self._obj) return create(getattr(self._obj.obj, self._name), self._obj)
except AttributeError: except AttributeError:
# happens e.g. in properties of # happens e.g. in properties of
# PyQt4.QtGui.QStyleOptionComboBox.currentText # PyQt4.QtGui.QStyleOptionComboBox.currentText

View File

@@ -65,6 +65,8 @@ def _load_fakes(module_name):
def _load_module(module): def _load_module(module):
module_name = module.__name__ module_name = module.__name__
if module_name == '__builtin__' and not is_py3k:
module_name = 'builtins'
try: try:
return modules[module_name] return modules[module_name]
except KeyError: except KeyError:
@@ -74,7 +76,7 @@ def _load_module(module):
source = f.read() source = f.read()
except IOError: except IOError:
return {} return {}
module = Parser(source).module module = Parser(source, module_name).module
modules[module_name] = module modules[module_name] = module
return module return module
@@ -82,7 +84,7 @@ def _load_module(module):
def get_faked(module, obj): def get_faked(module, obj):
def from_scope(scope, obj): def from_scope(scope, obj):
for s in scope.subscopes: for s in scope.subscopes:
if s.name == obj.name: if str(s.name) == obj.__name__:
return s return s
mod = _load_module(module) mod = _load_module(module)

View File

@@ -1,4 +1,5 @@
from jedi._compatibility import builtins from jedi._compatibility import builtins
from jedi.parser.representation import Function
from jedi.evaluate import compiled from jedi.evaluate import compiled
from jedi.evaluate import Evaluator from jedi.evaluate import Evaluator
@@ -13,3 +14,7 @@ def test_simple():
assert len(objs) == 1 assert len(objs) == 1
assert objs[0].obj is str assert objs[0].obj is str
assert objs[0].instantiated is True assert objs[0].instantiated is True
def test_fake_loading():
assert isinstance(compiled.create(reversed), Function)