forked from VimPlug/jedi
Use CheckAttribute descriptor more in CompiledObject to avoid duplicate code.
This commit is contained in:
@@ -46,18 +46,13 @@ class CompiledObject(Base):
|
|||||||
self.obj = obj
|
self.obj = obj
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
|
|
||||||
@property
|
@CheckAttribute
|
||||||
def py__call__(self):
|
def py__call__(self, params):
|
||||||
def actual(params):
|
if inspect.isclass(self.obj):
|
||||||
if inspect.isclass(self.obj):
|
from jedi.evaluate.representation import Instance
|
||||||
from jedi.evaluate.representation import Instance
|
return set([Instance(self._evaluator, self, params)])
|
||||||
return set([Instance(self._evaluator, self, params)])
|
else:
|
||||||
else:
|
return set(self._execute_function(params))
|
||||||
return set(self._execute_function(params))
|
|
||||||
|
|
||||||
# Might raise an AttributeError, which is intentional.
|
|
||||||
self.obj.__call__
|
|
||||||
return actual
|
|
||||||
|
|
||||||
@CheckAttribute
|
@CheckAttribute
|
||||||
def py__class__(self):
|
def py__class__(self):
|
||||||
@@ -168,32 +163,22 @@ class CompiledObject(Base):
|
|||||||
else:
|
else:
|
||||||
raise KeyError("CompiledObject doesn't have an attribute '%s'." % name)
|
raise KeyError("CompiledObject doesn't have an attribute '%s'." % name)
|
||||||
|
|
||||||
@property
|
@CheckAttribute
|
||||||
def py__getitem__(self):
|
def py__getitem__(self, index):
|
||||||
if not hasattr(self.obj, '__getitem__'):
|
if type(self.obj) not in (str, list, tuple, unicode, bytes, bytearray, dict):
|
||||||
raise AttributeError('No __getitem__ on %s' % self.obj)
|
# Get rid of side effects, we won't call custom `__getitem__`s.
|
||||||
|
return set()
|
||||||
|
|
||||||
def actual(index):
|
return set([create(self._evaluator, self.obj[index])])
|
||||||
if type(self.obj) not in (str, list, tuple, unicode, bytes, bytearray, dict):
|
|
||||||
# Get rid of side effects, we won't call custom `__getitem__`s.
|
|
||||||
return set()
|
|
||||||
|
|
||||||
return set([create(self._evaluator, self.obj[index])])
|
@CheckAttribute
|
||||||
return actual
|
|
||||||
|
|
||||||
@property
|
|
||||||
def py__iter__(self):
|
def py__iter__(self):
|
||||||
if not hasattr(self.obj, '__iter__'):
|
if type(self.obj) not in (str, list, tuple, unicode, bytes, bytearray, dict):
|
||||||
raise AttributeError('No __iter__ on %s' % self.obj)
|
# Get rid of side effects, we won't call custom `__getitem__`s.
|
||||||
|
return
|
||||||
|
|
||||||
def actual():
|
for part in self.obj:
|
||||||
if type(self.obj) not in (str, list, tuple, unicode, bytes, bytearray, dict):
|
yield set([create(self._evaluator, part)])
|
||||||
# Get rid of side effects, we won't call custom `__getitem__`s.
|
|
||||||
return
|
|
||||||
|
|
||||||
for part in self.obj:
|
|
||||||
yield set([create(self._evaluator, part)])
|
|
||||||
return actual
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user