Fix for all python versions

This commit is contained in:
Dave Halter
2018-02-21 01:23:50 +01:00
parent c1d06f4638
commit 2d4636da5b
+14 -10
View File
@@ -1,12 +1,13 @@
import inspect import inspect
import types import types
import sys import sys
from textwrap import dedent
import operator as op import operator as op
from collections import namedtuple from collections import namedtuple
from jedi import debug from jedi import debug
from jedi._compatibility import unicode, is_py3, is_py34, builtins, \ from jedi._compatibility import unicode, is_py3, is_py34, builtins, \
py_version, force_unicode, u, print_to_stderr py_version, force_unicode, print_to_stderr
from jedi.evaluate.compiled.getattr_static import getattr_static from jedi.evaluate.compiled.getattr_static import getattr_static
from jedi.evaluate.utils import dotted_from_fs_path from jedi.evaluate.utils import dotted_from_fs_path
@@ -448,22 +449,25 @@ def _is_class_instance(obj):
if py_version >= 35: if py_version >= 35:
async def _coroutine(): pass exec(compile(dedent("""
_coroutine = _coroutine() async def _coroutine(): pass
CoroutineType = type(_coroutine) _coroutine = _coroutine()
_coroutine.close() # Prevent ResourceWarning CoroutineType = type(_coroutine)
_coroutine.close() # Prevent ResourceWarning
"""), 'blub', 'exec'))
else: else:
_coroutine = None _coroutine = None
if py_version >= 36: if py_version >= 36:
async def _async_generator(): exec(compile(dedent("""
yield async def _async_generator():
_async_generator = _async_generator() yield
AsyncGeneratorType = type(_async_generator) _async_generator = _async_generator()
AsyncGeneratorType = type(_async_generator)
"""), 'blub', 'exec'))
else: else:
_async_generator = None _async_generator = None
class _SPECIAL_OBJECTS(object): class _SPECIAL_OBJECTS(object):
FUNCTION_CLASS = types.FunctionType FUNCTION_CLASS = types.FunctionType
METHOD_CLASS = type(DirectObjectAccess.py__bool__) METHOD_CLASS = type(DirectObjectAccess.py__bool__)