From b5e145321e4946447dca0ea28ed96333f3eccfa0 Mon Sep 17 00:00:00 2001 From: karosis88 Date: Thu, 10 Aug 2023 09:15:38 +0300 Subject: [PATCH 1/3] Fail tests if there is unused sub in unasync --- unasync.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/unasync.py b/unasync.py index d3607cd4..791e9ca8 100755 --- a/unasync.py +++ b/unasync.py @@ -33,10 +33,14 @@ for regex, repl in SUBS ] +USED_SUBS = set() def unasync_line(line): - for regex, repl in COMPILED_SUBS: + for index, (regex, repl) in enumerate(COMPILED_SUBS): + old_line = line line = re.sub(regex, repl, line) + if old_line != line: + USED_SUBS.add(index) return line @@ -81,6 +85,18 @@ def main(): unasync_dir("httpcore/_async", "httpcore/_sync", check_only=check_only) unasync_dir("tests/_async", "tests/_sync", check_only=check_only) + if len(USED_SUBS) != len(SUBS): + unused_subs = [] + + for i in range(len(SUBS)): + if i not in USED_SUBS: + unused_subs.append(SUBS[i]) + + from pprint import pprint + print("These patterns were not used:") + pprint(unused_subs) + exit(1) + if __name__ == '__main__': main() From b0c8ac5e281025545ff04ca4057be4c792837090 Mon Sep 17 00:00:00 2001 From: karosis88 Date: Thu, 10 Aug 2023 09:23:22 +0300 Subject: [PATCH 2/3] Remove patterns --- unasync.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/unasync.py b/unasync.py index 791e9ca8..81500449 100755 --- a/unasync.py +++ b/unasync.py @@ -6,9 +6,7 @@ SUBS = [ ('from .._backends.auto import AutoBackend', 'from .._backends.sync import SyncBackend'), ('import trio as concurrency', 'from tests import concurrency'), - ('AsyncByteStream', 'SyncByteStream'), ('AsyncIterator', 'Iterator'), - ('AutoBackend', 'SyncBackend'), ('Async([A-Z][A-Za-z0-9_]*)', r'\2'), ('async def', 'def'), ('async with', 'with'), @@ -16,8 +14,6 @@ ('await ', ''), ('handle_async_request', 'handle_request'), ('aclose', 'close'), - ('aclose_func', 'close_func'), - ('aiterator', 'iterator'), ('aiter_stream', 'iter_stream'), ('aread', 'read'), ('asynccontextmanager', 'contextmanager'), From ec7a887d2232d80cef05f899a93fd23c9aef94bd Mon Sep 17 00:00:00 2001 From: karosis88 Date: Fri, 11 Aug 2023 08:25:51 +0300 Subject: [PATCH 3/3] Simplify unasync --- unasync.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/unasync.py b/unasync.py index 81500449..5a5627d7 100755 --- a/unasync.py +++ b/unasync.py @@ -2,6 +2,7 @@ import os import re import sys +from pprint import pprint SUBS = [ ('from .._backends.auto import AutoBackend', 'from .._backends.sync import SyncBackend'), @@ -82,13 +83,8 @@ def main(): unasync_dir("tests/_async", "tests/_sync", check_only=check_only) if len(USED_SUBS) != len(SUBS): - unused_subs = [] + unused_subs = [SUBS[i] for i in range(len(SUBS)) if i not in USED_SUBS] - for i in range(len(SUBS)): - if i not in USED_SUBS: - unused_subs.append(SUBS[i]) - - from pprint import pprint print("These patterns were not used:") pprint(unused_subs) exit(1)