Don't try to pickle ellipsis

This commit is contained in:
Dave Halter
2017-12-11 20:55:34 +01:00
parent fa2712a128
commit b196c6849b
5 changed files with 10 additions and 14 deletions

View File

@@ -93,7 +93,7 @@ class Context(BaseContext):
except ValueError: except ValueError:
pass pass
if type(index) not in (float, int, str, unicode, slice, type(Ellipsis)): if type(index) not in (float, int, str, unicode, slice):
# If the index is not clearly defined, we have to get all the # If the index is not clearly defined, we have to get all the
# possiblities. # possiblities.
if isinstance(self, AbstractIterable) and self.array_type == 'dict': if isinstance(self, AbstractIterable) and self.array_type == 'dict':

View File

@@ -1,8 +1,7 @@
from jedi._compatibility import builtins as _builtins from jedi._compatibility import unicode
from jedi.evaluate.compiled.context import CompiledObject, CompiledName, \ from jedi.evaluate.compiled.context import CompiledObject, CompiledName, \
CompiledObjectFilter, CompiledContextName, create_from_access_path, \ CompiledObjectFilter, CompiledContextName, create_from_access_path, \
create_from_name create_from_name
from jedi.evaluate.compiled import access
def builtin_from_name(evaluator, string): def builtin_from_name(evaluator, string):
@@ -15,7 +14,7 @@ def create_simple_object(evaluator, obj):
Only allows creations of objects that are easily picklable across Python Only allows creations of objects that are easily picklable across Python
versions. versions.
""" """
assert isinstance(obj, (int, float, str, bytes, slice, complex, type(Ellipsis))) assert isinstance(obj, (int, float, str, bytes, unicode, slice, complex))
return create_from_access_path( return create_from_access_path(
evaluator, evaluator,
evaluator.compiled_subprocess.create_simple_object(obj) evaluator.compiled_subprocess.create_simple_object(obj)

View File

@@ -155,7 +155,7 @@ class AccessPath(object):
def create_access_path(evaluator, obj): def create_access_path(evaluator, obj):
access = create_access(evaluator, obj) access = create_access(evaluator, obj)
return AccessPath(access._get_access_path_tuples()) return AccessPath(access.get_access_path_tuples())
class DirectObjectAccess(object): class DirectObjectAccess(object):
@@ -274,7 +274,7 @@ class DirectObjectAccess(object):
return None return None
def get_safe_value(self): def get_safe_value(self):
if type(self._obj) in (bool, bytes, float, int, str, unicode, slice, type(Ellipsis)): if type(self._obj) in (bool, bytes, float, int, str, unicode, slice):
return self._obj return self._obj
raise ValueError("Object is type %s and not simple" % type(self._obj)) raise ValueError("Object is type %s and not simple" % type(self._obj))
@@ -290,7 +290,7 @@ class DirectObjectAccess(object):
# Everything else... # Everything else...
return 'instance' return 'instance'
def _get_access_path_tuples(self): def get_access_path_tuples(self):
return [ return [
(getattr(o, '__name__', None), create_access(self._evaluator, o)) (getattr(o, '__name__', None), create_access(self._evaluator, o))
for o in self._get_objects_path() for o in self._get_objects_path()

View File

@@ -188,7 +188,7 @@ class _CompiledSubprocess(_Subprocess):
self._evaluator_deletion_queue.append(evaluator_id) self._evaluator_deletion_queue.append(evaluator_id)
class Listener(): class Listener(object):
def __init__(self): def __init__(self):
self._evaluators = {} self._evaluators = {}
# TODO refactor so we don't need to process anymore just handle # TODO refactor so we don't need to process anymore just handle
@@ -263,9 +263,10 @@ class AccessHandle(object):
self.id = state self.id = state
def __getattr__(self, name): def __getattr__(self, name):
if name in ('id', '_subprocess', 'access'): if name in ('id', 'access') or name.startswith('_'):
raise AttributeError("Something went wrong with unpickling") raise AttributeError("Something went wrong with unpickling")
#print >> sys.stderr, name
#print('getattr', name, file=sys.stderr) #print('getattr', name, file=sys.stderr)
def compiled_method(*args, **kwargs): def compiled_method(*args, **kwargs):
return self._subprocess.get_compiled_method_return(self.id, name, *args, **kwargs) return self._subprocess.get_compiled_method_return(self.id, name, *args, **kwargs)

View File

@@ -87,10 +87,6 @@ def test_tokenizer_with_string_literal_backslash():
def test_ellipsis(): def test_ellipsis():
def_, = jedi.Script(dedent("""\ def_, = jedi.Script('x=...;x').goto_definitions()
class Foo():
def __getitem__(self, index):
return index
Foo()[...]""")).goto_definitions()
assert def_.name == 'ellipsis' assert def_.name == 'ellipsis'