Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/unasync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
"__aiter__": "__iter__",
"__anext__": "__next__",
"asynccontextmanager": "contextmanager",
"AsyncIterable": "Iterable",
"AsyncIterator": "Iterator",
"AsyncGenerator": "Generator",
# TODO StopIteration is still accepted in Python 2, but the right change
# is 'raise StopAsyncIteration' -> 'return' since we want to use unasynced
# code in Python 3.7+
Expand Down Expand Up @@ -68,8 +71,16 @@ def unasync_tokens(tokens):
# `print( stuff)`
used_space = space
else:
if toknum == std_tokenize.NAME and tokval in ASYNC_TO_SYNC:
tokval = ASYNC_TO_SYNC[tokval]
if toknum == std_tokenize.NAME:
if tokval in ASYNC_TO_SYNC:
tokval = ASYNC_TO_SYNC[tokval]
# Convert classes prefixed with 'Async' into 'Sync'
elif (
len(tokval) > 5
and tokval.startswith("Async")
and tokval[5].isupper()
):
tokval = "Sync" + tokval[5:]
if used_space is None:
used_space = space
yield (used_space, tokval)
Expand Down
3 changes: 3 additions & 0 deletions tests/data/async/classes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class AsyncSocket(object):
async def send_all(self, data):
...
5 changes: 5 additions & 0 deletions tests/data/async/typing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import typing

typing.AsyncIterable[bytes]
typing.AsyncIterator[bytes]
typing.AsyncGenerator[bytes]
3 changes: 3 additions & 0 deletions tests/data/sync/classes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class SyncSocket(object):
def send_all(self, data):
...
5 changes: 5 additions & 0 deletions tests/data/sync/typing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import typing

typing.Iterable[bytes]
typing.Iterator[bytes]
typing.Generator[bytes]