1
0
forked from VimPlug/jedi

Use IterableWrapper in the iterable module to be able to add methods like is_class quickly.

This commit is contained in:
Dave Halter
2014-08-20 14:01:41 +02:00
parent 442a1a1d08
commit 0e66aef511
2 changed files with 11 additions and 6 deletions

View File

@@ -35,7 +35,12 @@ from jedi.cache import underscore_memoization
from jedi.evaluate import analysis
class Generator(use_metaclass(CachedMetaClass, pr.Base)):
class IterableWrapper(pr.Base):
def is_class(self):
return False
class Generator(use_metaclass(CachedMetaClass, IterableWrapper)):
"""Handling of `yield` functions."""
def __init__(self, evaluator, func, var_args):
super(Generator, self).__init__()
@@ -91,7 +96,7 @@ class Generator(use_metaclass(CachedMetaClass, pr.Base)):
return "<%s of %s>" % (type(self).__name__, self.func)
class GeneratorMethod(object):
class GeneratorMethod(IterableWrapper):
"""``__next__`` and ``send`` methods."""
def __init__(self, generator, builtin_func):
self._builtin_func = builtin_func
@@ -114,7 +119,7 @@ class GeneratorComprehension(Generator):
return self._evaluator.eval_statement_element(self.comprehension)
class Array(use_metaclass(CachedMetaClass, pr.Base)):
class Array(use_metaclass(CachedMetaClass, IterableWrapper)):
"""
Used as a mirror to pr.Array, if needed. It defines some getter
methods which are important in this module.
@@ -216,7 +221,7 @@ class Array(use_metaclass(CachedMetaClass, pr.Base)):
return "<e%s of %s>" % (type(self).__name__, self._array)
class ArrayMethod(object):
class ArrayMethod(IterableWrapper):
"""
A name, e.g. `list.append`, it is used to access the original array
methods.
@@ -423,7 +428,7 @@ def check_array_instances(evaluator, instance):
return [ai]
class ArrayInstance(pr.Base):
class ArrayInstance(IterableWrapper):
"""
Used for the usage of set() and list().
This is definitely a hack, but a good one :-)

View File

@@ -131,7 +131,7 @@ def builtins_isinstance(evaluator, obj, params):
classes = []
# Check for tuples.
for cls_or_tup in raw_classes:
if isinstance(cls_or_tup, er.Class):
if cls_or_tup.is_class():
classes.append(cls_or_tup)
else:
classes += iterable.get_iterator_types([cls_or_tup])