Skip to content

Commit

Permalink
Fixed is_thenable in coroutines. Fixed #17
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed Dec 2, 2016
1 parent d163aed commit 8b0d5da
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion promise/promise.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,4 +497,6 @@ def is_thenable(obj):
"""
return isinstance(obj, Promise) or is_future(obj) or (
hasattr(obj, "done") and callable(getattr(obj, "done"))) or (
hasattr(obj, "then") and callable(getattr(obj, "then")))
hasattr(obj, "then") and callable(getattr(obj, "then"))) or (
iscoroutine(obj))

11 changes: 10 additions & 1 deletion tests/test_awaitable_35.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
import asyncio
from promise import Promise, promisify
from promise import Promise, promisify, is_thenable


@pytest.mark.asyncio
Expand All @@ -17,6 +17,15 @@ async def my_coroutine():
assert await promisify(my_coroutine())


@pytest.mark.asyncio
async def test_coroutine_is_thenable():
async def my_coroutine():
await asyncio.sleep(.01)
return True

assert is_thenable(my_coroutine())


@pytest.mark.asyncio
async def test_promisify_future():
future = asyncio.Future()
Expand Down

0 comments on commit 8b0d5da

Please sign in to comment.