forked from VimPlug/jedi
Fix a few more tests
This commit is contained in:
@@ -205,7 +205,12 @@ class CompiledObject(Context):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def get_safe_value(self, default=_sentinel):
|
def get_safe_value(self, default=_sentinel):
|
||||||
return self.access.get_safe_value(default=default)
|
try:
|
||||||
|
return self.access.get_safe_value()
|
||||||
|
except ValueError:
|
||||||
|
if default == _sentinel:
|
||||||
|
raise
|
||||||
|
return default
|
||||||
|
|
||||||
def execute_operation(self, other, operator):
|
def execute_operation(self, other, operator):
|
||||||
return _create_from_access(
|
return _create_from_access(
|
||||||
@@ -565,8 +570,6 @@ def _create(evaluator, access, parent_context=None, faked=None):
|
|||||||
parent_context = create(evaluator, _builtins)
|
parent_context = create(evaluator, _builtins)
|
||||||
return create(evaluator, access, parent_context)
|
return create(evaluator, access, parent_context)
|
||||||
|
|
||||||
if access._obj == str:
|
|
||||||
print('OOOOOOOOOO', id(access), id(parent_context), id(faked))
|
|
||||||
return CompiledObject(evaluator, access, parent_context, faked)
|
return CompiledObject(evaluator, access, parent_context, faked)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ def compiled_objects_cache(attribute_name):
|
|||||||
Caching the id has the advantage that an object doesn't need to be
|
Caching the id has the advantage that an object doesn't need to be
|
||||||
hashable.
|
hashable.
|
||||||
"""
|
"""
|
||||||
def wrapper(evaluator, obj):
|
def wrapper(evaluator, obj, parent_context=None):
|
||||||
cache = getattr(evaluator, attribute_name)
|
cache = getattr(evaluator, attribute_name)
|
||||||
# Do a very cheap form of caching here.
|
# Do a very cheap form of caching here.
|
||||||
key = id(obj)
|
key = id(obj)
|
||||||
@@ -91,9 +91,13 @@ def compiled_objects_cache(attribute_name):
|
|||||||
cache[key]
|
cache[key]
|
||||||
return cache[key][0]
|
return cache[key][0]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
# TODO wuaaaarrghhhhhhhh
|
||||||
|
if attribute_name == 'mixed_cache':
|
||||||
|
result = func(evaluator, obj, parent_context)
|
||||||
|
else:
|
||||||
result = func(evaluator, obj)
|
result = func(evaluator, obj)
|
||||||
# Need to cache all of them, otherwise the id could be overwritten.
|
# Need to cache all of them, otherwise the id could be overwritten.
|
||||||
cache[key] = result, obj
|
cache[key] = result, obj, parent_context
|
||||||
return result
|
return result
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
@@ -214,10 +218,9 @@ class DirectObjectAccess(object):
|
|||||||
raise
|
raise
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_safe_value(self, default=_sentinel):
|
def get_safe_value(self):
|
||||||
if type(self._obj) in (float, int, str, unicode, slice, type(Ellipsis)):
|
if type(self._obj) in (float, int, str, unicode, slice, type(Ellipsis)):
|
||||||
return self._obj
|
return self._obj
|
||||||
if default == _sentinel:
|
|
||||||
raise ValueError
|
raise ValueError
|
||||||
|
|
||||||
def get_api_type(self):
|
def get_api_type(self):
|
||||||
|
|||||||
@@ -109,7 +109,8 @@ def _load_module(evaluator, path, python_object):
|
|||||||
).get_root_node()
|
).get_root_node()
|
||||||
python_module = inspect.getmodule(python_object)
|
python_module = inspect.getmodule(python_object)
|
||||||
|
|
||||||
evaluator.modules[python_module.__name__] = module
|
# TODO we should actually make something like this possible.
|
||||||
|
#evaluator.modules[python_module.__name__] = module
|
||||||
return module
|
return module
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -250,7 +250,7 @@ class DictComprehension(ArrayMixin, Comprehension):
|
|||||||
for keys, values in self._iterate():
|
for keys, values in self._iterate():
|
||||||
for k in keys:
|
for k in keys:
|
||||||
if isinstance(k, compiled.CompiledObject):
|
if isinstance(k, compiled.CompiledObject):
|
||||||
if k.obj == index:
|
if k.get_safe_value(default=object()) == index:
|
||||||
return values
|
return values
|
||||||
return self.dict_values()
|
return self.dict_values()
|
||||||
|
|
||||||
|
|||||||
@@ -229,7 +229,6 @@ def builtins_isinstance(evaluator, objects, types, arguments):
|
|||||||
|
|
||||||
for cls_or_tup in types:
|
for cls_or_tup in types:
|
||||||
if cls_or_tup.is_class():
|
if cls_or_tup.is_class():
|
||||||
print(id(mro[0]), mro[0], id(cls_or_tup), cls_or_tup)
|
|
||||||
bool_results.add(cls_or_tup in mro)
|
bool_results.add(cls_or_tup in mro)
|
||||||
elif cls_or_tup.name.string_name == 'tuple' \
|
elif cls_or_tup.name.string_name == 'tuple' \
|
||||||
and cls_or_tup.get_root_context() == evaluator.BUILTINS:
|
and cls_or_tup.get_root_context() == evaluator.BUILTINS:
|
||||||
|
|||||||
@@ -12,32 +12,25 @@ from jedi.parser_utils import clean_scope_docstring
|
|||||||
from jedi import Script
|
from jedi import Script
|
||||||
|
|
||||||
|
|
||||||
def _evaluator():
|
def test_simple(evaluator):
|
||||||
return Evaluator(parso.load_grammar(), Project())
|
obj = compiled.create(evaluator, '_str_')
|
||||||
|
|
||||||
|
|
||||||
def test_simple():
|
|
||||||
e = _evaluator()
|
|
||||||
bltn = compiled.CompiledObject(e, builtins)
|
|
||||||
obj = compiled.CompiledObject(e, '_str_', bltn)
|
|
||||||
upper, = obj.py__getattribute__('upper')
|
upper, = obj.py__getattribute__('upper')
|
||||||
objs = list(upper.execute_evaluated())
|
objs = list(upper.execute_evaluated())
|
||||||
assert len(objs) == 1
|
assert len(objs) == 1
|
||||||
assert isinstance(objs[0], instance.CompiledInstance)
|
assert isinstance(objs[0], instance.CompiledInstance)
|
||||||
|
|
||||||
|
|
||||||
def test_fake_loading():
|
def test_fake_loading(evaluator):
|
||||||
e = _evaluator()
|
assert isinstance(compiled.create(evaluator, next), FunctionContext)
|
||||||
assert isinstance(compiled.create(e, next), FunctionContext)
|
|
||||||
|
|
||||||
builtin = compiled.get_special_object(e, 'BUILTINS')
|
builtin = compiled.get_special_object(evaluator, 'BUILTINS')
|
||||||
string, = builtin.py__getattribute__('str')
|
string, = builtin.py__getattribute__('str')
|
||||||
from_name = compiled._create_from_name(e, builtin, string, '__init__')
|
from_name = compiled._create_from_name(evaluator, builtin, string, '__init__')
|
||||||
assert isinstance(from_name, FunctionContext)
|
assert isinstance(from_name, FunctionContext)
|
||||||
|
|
||||||
|
|
||||||
def test_fake_docstr():
|
def test_fake_docstr(evaluator):
|
||||||
node = compiled.create(_evaluator(), next).tree_node
|
node = compiled.create(evaluator, next).tree_node
|
||||||
assert clean_scope_docstring(node) == next.__doc__
|
assert clean_scope_docstring(node) == next.__doc__
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user