mirror of https://github.com/python/cpython
Merge 3.5 (Issue #24400)
This commit is contained in:
commit
93a3252c9c
|
@ -303,16 +303,6 @@ attributes:
|
||||||
.. versionadded:: 3.5
|
.. versionadded:: 3.5
|
||||||
|
|
||||||
|
|
||||||
.. function:: isawaitable(object)
|
|
||||||
|
|
||||||
Return true if the object can be used in :keyword:`await`
|
|
||||||
expression.
|
|
||||||
|
|
||||||
See also :class:`collections.abc.Awaitable`.
|
|
||||||
|
|
||||||
.. versionadded:: 3.5
|
|
||||||
|
|
||||||
|
|
||||||
.. function:: istraceback(object)
|
.. function:: istraceback(object)
|
||||||
|
|
||||||
Return true if the object is a traceback.
|
Return true if the object is a traceback.
|
||||||
|
|
|
@ -527,9 +527,8 @@ inspect
|
||||||
* New argument ``follow_wrapped`` for :func:`inspect.signature`.
|
* New argument ``follow_wrapped`` for :func:`inspect.signature`.
|
||||||
(Contributed by Yury Selivanov in :issue:`20691`.)
|
(Contributed by Yury Selivanov in :issue:`20691`.)
|
||||||
|
|
||||||
* New :func:`~inspect.iscoroutine`, :func:`~inspect.iscoroutinefunction`,
|
* New :func:`~inspect.iscoroutine` and :func:`~inspect.iscoroutinefunction`
|
||||||
and :func:`~inspect.isawaitable` functions. (Contributed by Yury Selivanov
|
functions. (Contributed by Yury Selivanov in :issue:`24017`.)
|
||||||
in :issue:`24017`.)
|
|
||||||
|
|
||||||
* New :func:`~inspect.getcoroutinelocals` and :func:`~inspect.getcoroutinestate`
|
* New :func:`~inspect.getcoroutinelocals` and :func:`~inspect.getcoroutinestate`
|
||||||
functions. (Contributed by Yury Selivanov in :issue:`24400`.)
|
functions. (Contributed by Yury Selivanov in :issue:`24400`.)
|
||||||
|
|
|
@ -186,10 +186,6 @@ def iscoroutinefunction(object):
|
||||||
return bool((isfunction(object) or ismethod(object)) and
|
return bool((isfunction(object) or ismethod(object)) and
|
||||||
object.__code__.co_flags & CO_COROUTINE)
|
object.__code__.co_flags & CO_COROUTINE)
|
||||||
|
|
||||||
def isawaitable(object):
|
|
||||||
"""Return true if the object can be used in "await" expression."""
|
|
||||||
return isinstance(object, collections.abc.Awaitable)
|
|
||||||
|
|
||||||
def isgenerator(object):
|
def isgenerator(object):
|
||||||
"""Return true if the object is a generator.
|
"""Return true if the object is a generator.
|
||||||
|
|
||||||
|
|
|
@ -159,31 +159,6 @@ class TestPredicates(IsTestBase):
|
||||||
|
|
||||||
coro.close(); gen_coro.close() # silence warnings
|
coro.close(); gen_coro.close() # silence warnings
|
||||||
|
|
||||||
def test_isawaitable(self):
|
|
||||||
def gen(): yield
|
|
||||||
self.assertFalse(inspect.isawaitable(gen()))
|
|
||||||
|
|
||||||
coro = coroutine_function_example(1)
|
|
||||||
gen_coro = gen_coroutine_function_example(1)
|
|
||||||
|
|
||||||
self.assertTrue(
|
|
||||||
inspect.isawaitable(coro))
|
|
||||||
self.assertTrue(
|
|
||||||
inspect.isawaitable(gen_coro))
|
|
||||||
|
|
||||||
class Future:
|
|
||||||
def __await__():
|
|
||||||
pass
|
|
||||||
self.assertTrue(inspect.isawaitable(Future()))
|
|
||||||
self.assertFalse(inspect.isawaitable(Future))
|
|
||||||
|
|
||||||
class NotFuture: pass
|
|
||||||
not_fut = NotFuture()
|
|
||||||
not_fut.__await__ = lambda: None
|
|
||||||
self.assertFalse(inspect.isawaitable(not_fut))
|
|
||||||
|
|
||||||
coro.close(); gen_coro.close() # silence warnings
|
|
||||||
|
|
||||||
def test_isroutine(self):
|
def test_isroutine(self):
|
||||||
self.assertTrue(inspect.isroutine(mod.spam))
|
self.assertTrue(inspect.isroutine(mod.spam))
|
||||||
self.assertTrue(inspect.isroutine([].count))
|
self.assertTrue(inspect.isroutine([].count))
|
||||||
|
|
Loading…
Reference in New Issue