1
0
forked from VimPlug/jedi

Fix a few more tests

This commit is contained in:
Dave Halter
2017-11-26 22:07:13 +01:00
parent 85ce57a863
commit accf20226d
6 changed files with 26 additions and 27 deletions

View File

@@ -205,7 +205,12 @@ class CompiledObject(Context):
)
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):
return _create_from_access(
@@ -565,8 +570,6 @@ def _create(evaluator, access, parent_context=None, faked=None):
parent_context = create(evaluator, _builtins)
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)

View File

@@ -83,7 +83,7 @@ def compiled_objects_cache(attribute_name):
Caching the id has the advantage that an object doesn't need to be
hashable.
"""
def wrapper(evaluator, obj):
def wrapper(evaluator, obj, parent_context=None):
cache = getattr(evaluator, attribute_name)
# Do a very cheap form of caching here.
key = id(obj)
@@ -91,9 +91,13 @@ def compiled_objects_cache(attribute_name):
cache[key]
return cache[key][0]
except KeyError:
result = func(evaluator, obj)
# TODO wuaaaarrghhhhhhhh
if attribute_name == 'mixed_cache':
result = func(evaluator, obj, parent_context)
else:
result = func(evaluator, obj)
# 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 wrapper
@@ -214,11 +218,10 @@ class DirectObjectAccess(object):
raise
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)):
return self._obj
if default == _sentinel:
raise ValueError
raise ValueError
def get_api_type(self):
obj = self._obj

View File

@@ -109,7 +109,8 @@ def _load_module(evaluator, path, python_object):
).get_root_node()
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

View File

@@ -250,7 +250,7 @@ class DictComprehension(ArrayMixin, Comprehension):
for keys, values in self._iterate():
for k in keys:
if isinstance(k, compiled.CompiledObject):
if k.obj == index:
if k.get_safe_value(default=object()) == index:
return values
return self.dict_values()

View File

@@ -229,7 +229,6 @@ def builtins_isinstance(evaluator, objects, types, arguments):
for cls_or_tup in types:
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)
elif cls_or_tup.name.string_name == 'tuple' \
and cls_or_tup.get_root_context() == evaluator.BUILTINS: