From de311b2f2d914a57ef499bdc0a401bdca3fc0056 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sun, 23 Sep 2018 23:22:33 +0200 Subject: [PATCH] Replace the Generator class for now --- jedi/evaluate/compiled/access.py | 29 ----------------------------- jedi/evaluate/context/iterable.py | 8 +++++++- jedi/evaluate/filters.py | 8 -------- 3 files changed, 7 insertions(+), 38 deletions(-) diff --git a/jedi/evaluate/compiled/access.py b/jedi/evaluate/compiled/access.py index fb2676bd..4f6f91e9 100644 --- a/jedi/evaluate/compiled/access.py +++ b/jedi/evaluate/compiled/access.py @@ -43,12 +43,6 @@ WrapperDescriptorType = type(set.__iter__) object_class_dict = type.__dict__["__dict__"].__get__(object) 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() # 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) -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): FUNCTION_CLASS = types.FunctionType BOUND_METHOD_CLASS = type(DirectObjectAccess(None, None).py__bool__) MODULE_CLASS = types.ModuleType - GENERATOR_OBJECT = _a_generator(1.0) BUILTINS = builtins diff --git a/jedi/evaluate/context/iterable.py b/jedi/evaluate/context/iterable.py index 72a622bd..a12cef7c 100644 --- a/jedi/evaluate/context/iterable.py +++ b/jedi/evaluate/context/iterable.py @@ -49,7 +49,13 @@ class IterableMixin(object): class GeneratorBase(BuiltinOverwrite, IterableMixin): 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('next', python_version_match=2) diff --git a/jedi/evaluate/filters.py b/jedi/evaluate/filters.py index 841bc975..ab9aaaa3 100644 --- a/jedi/evaluate/filters.py +++ b/jedi/evaluate/filters.py @@ -434,17 +434,9 @@ class AbstractObjectOverwrite(use_metaclass(_OverwriteMeta, object)): class BuiltinOverwrite(Context, AbstractObjectOverwrite): - special_object_identifier = None - def __init__(self, evaluator): 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): return self.get_object().py__class__()