mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-09 23:34:45 +08:00
Replace the Generator class for now
This commit is contained in:
@@ -43,12 +43,6 @@ WrapperDescriptorType = type(set.__iter__)
|
|||||||
object_class_dict = type.__dict__["__dict__"].__get__(object)
|
object_class_dict = type.__dict__["__dict__"].__get__(object)
|
||||||
ClassMethodDescriptorType = type(object_class_dict['__subclasshook__'])
|
ClassMethodDescriptorType = type(object_class_dict['__subclasshook__'])
|
||||||
|
|
||||||
def _a_generator(foo):
|
|
||||||
"""Used to have an object to return for generators."""
|
|
||||||
yield 42
|
|
||||||
yield foo
|
|
||||||
|
|
||||||
|
|
||||||
_sentinel = object()
|
_sentinel = object()
|
||||||
|
|
||||||
# Maps Python syntax to the operator module.
|
# Maps Python syntax to the operator module.
|
||||||
@@ -446,33 +440,10 @@ def _is_class_instance(obj):
|
|||||||
return cls != type and not issubclass(cls, NOT_CLASS_TYPES)
|
return cls != type and not issubclass(cls, NOT_CLASS_TYPES)
|
||||||
|
|
||||||
|
|
||||||
if py_version >= 35:
|
|
||||||
exec(compile(dedent("""
|
|
||||||
async def _coroutine(): pass
|
|
||||||
_coroutine = _coroutine()
|
|
||||||
CoroutineType = type(_coroutine)
|
|
||||||
_coroutine.close() # Prevent ResourceWarning
|
|
||||||
"""), 'blub', 'exec'))
|
|
||||||
_coroutine_wrapper = _coroutine.__await__()
|
|
||||||
else:
|
|
||||||
_coroutine = None
|
|
||||||
_coroutine_wrapper = None
|
|
||||||
|
|
||||||
if py_version >= 36:
|
|
||||||
exec(compile(dedent("""
|
|
||||||
async def _async_generator():
|
|
||||||
yield
|
|
||||||
_async_generator = _async_generator()
|
|
||||||
AsyncGeneratorType = type(_async_generator)
|
|
||||||
"""), 'blub', 'exec'))
|
|
||||||
else:
|
|
||||||
_async_generator = None
|
|
||||||
|
|
||||||
class _SPECIAL_OBJECTS(object):
|
class _SPECIAL_OBJECTS(object):
|
||||||
FUNCTION_CLASS = types.FunctionType
|
FUNCTION_CLASS = types.FunctionType
|
||||||
BOUND_METHOD_CLASS = type(DirectObjectAccess(None, None).py__bool__)
|
BOUND_METHOD_CLASS = type(DirectObjectAccess(None, None).py__bool__)
|
||||||
MODULE_CLASS = types.ModuleType
|
MODULE_CLASS = types.ModuleType
|
||||||
GENERATOR_OBJECT = _a_generator(1.0)
|
|
||||||
BUILTINS = builtins
|
BUILTINS = builtins
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,13 @@ class IterableMixin(object):
|
|||||||
|
|
||||||
class GeneratorBase(BuiltinOverwrite, IterableMixin):
|
class GeneratorBase(BuiltinOverwrite, IterableMixin):
|
||||||
array_type = None
|
array_type = None
|
||||||
special_object_identifier = u'GENERATOR_OBJECT'
|
|
||||||
|
@memoize_method
|
||||||
|
def get_object(self):
|
||||||
|
generator, = self.evaluator.typing_module \
|
||||||
|
.py__getattribute__('Generator') \
|
||||||
|
.execute_annotation()
|
||||||
|
return generator
|
||||||
|
|
||||||
@publish_method('send')
|
@publish_method('send')
|
||||||
@publish_method('next', python_version_match=2)
|
@publish_method('next', python_version_match=2)
|
||||||
|
|||||||
@@ -434,17 +434,9 @@ class AbstractObjectOverwrite(use_metaclass(_OverwriteMeta, object)):
|
|||||||
|
|
||||||
|
|
||||||
class BuiltinOverwrite(Context, AbstractObjectOverwrite):
|
class BuiltinOverwrite(Context, AbstractObjectOverwrite):
|
||||||
special_object_identifier = None
|
|
||||||
|
|
||||||
def __init__(self, evaluator):
|
def __init__(self, evaluator):
|
||||||
super(BuiltinOverwrite, self).__init__(evaluator, evaluator.builtins_module)
|
super(BuiltinOverwrite, self).__init__(evaluator, evaluator.builtins_module)
|
||||||
|
|
||||||
@memoize_method
|
|
||||||
def get_object(self):
|
|
||||||
from jedi.evaluate import compiled
|
|
||||||
assert self.special_object_identifier
|
|
||||||
return compiled.get_special_object(self.evaluator, self.special_object_identifier)
|
|
||||||
|
|
||||||
def py__class__(self):
|
def py__class__(self):
|
||||||
return self.get_object().py__class__()
|
return self.get_object().py__class__()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user