From ab7d759af931c799308276102f0bcde3b779429f Mon Sep 17 00:00:00 2001 From: Sourcery AI <> Date: Sat, 9 Dec 2023 22:33:45 +0000 Subject: [PATCH] 'Refactored by Sourcery' --- src/unasync/__init__.py | 16 +++++++++------- tests/data/async/simple.py | 7 +------ tests/data/sync/simple.py | 7 +------ tests/test_unasync.py | 8 ++++---- 4 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/unasync/__init__.py b/src/unasync/__init__.py index ffc9205..d2c0970 100644 --- a/src/unasync/__init__.py +++ b/src/unasync/__init__.py @@ -57,11 +57,14 @@ def _match(self, filepath): if len_from_segments > len(file_segments): return False - for i in range(len(file_segments) - len_from_segments + 1): - if file_segments[i : i + len_from_segments] == from_segments: - return len_from_segments, i - - return False + return next( + ( + (len_from_segments, i) + for i in range(len(file_segments) - len_from_segments + 1) + if file_segments[i : i + len_from_segments] == from_segments + ), + False, + ) def _unasync_file(self, filepath): with open(filepath, "rb") as f: @@ -105,9 +108,8 @@ def _unasync_tokens(self, tokens): def _unasync_name(self, name): if name in self.token_replacements: return self.token_replacements[name] - # Convert classes prefixed with 'Async' into 'Sync' elif len(name) > 5 and name.startswith("Async") and name[5].isupper(): - return "Sync" + name[5:] + return f"Sync{name[5:]}" return name diff --git a/tests/data/async/simple.py b/tests/data/async/simple.py index a4c2392..31f336c 100644 --- a/tests/data/async/simple.py +++ b/tests/data/async/simple.py @@ -5,12 +5,7 @@ def __init__(self, a, b): self.s = "UTF-8: ❄" async def get_a_b(self): - # fmt: off - s = "a is %s b is %s" % \ - (self.a, - self.b) - # fmt: on - return s + return f"a is {self.a} b is {self.b}" async def f(self): return await 1 diff --git a/tests/data/sync/simple.py b/tests/data/sync/simple.py index 13d66eb..175c57b 100644 --- a/tests/data/sync/simple.py +++ b/tests/data/sync/simple.py @@ -5,12 +5,7 @@ def __init__(self, a, b): self.s = "UTF-8: ❄" def get_a_b(self): - # fmt: off - s = "a is %s b is %s" % \ - (self.a, - self.b) - # fmt: on - return s + return f"a is {self.a} b is {self.b}" def f(self): return 1 diff --git a/tests/test_unasync.py b/tests/test_unasync.py index 35e0c6c..7323eb2 100644 --- a/tests/test_unasync.py +++ b/tests/test_unasync.py @@ -66,7 +66,7 @@ def test_unasync_files(tmpdir): def test_build_py_modules(tmpdir): source_modules_dir = os.path.join(TEST_DIR, "example_mod") - mod_dir = str(tmpdir) + "/" + "example_mod" + mod_dir = f"{str(tmpdir)}/example_mod" shutil.copytree(source_modules_dir, mod_dir) env = copy.copy(os.environ) @@ -86,7 +86,7 @@ def test_build_py_modules(tmpdir): def test_build_py_packages(tmpdir): source_pkg_dir = os.path.join(TEST_DIR, "example_pkg") - pkg_dir = str(tmpdir) + "/" + "example_pkg" + pkg_dir = f"{str(tmpdir)}/example_pkg" shutil.copytree(source_pkg_dir, pkg_dir) env = copy.copy(os.environ) @@ -103,7 +103,7 @@ def test_build_py_packages(tmpdir): def test_project_structure_after_build_py_packages(tmpdir): source_pkg_dir = os.path.join(TEST_DIR, "example_pkg") - pkg_dir = str(tmpdir) + "/" + "example_pkg" + pkg_dir = f"{str(tmpdir)}/example_pkg" shutil.copytree(source_pkg_dir, pkg_dir) env = copy.copy(os.environ) @@ -123,7 +123,7 @@ def test_project_structure_after_build_py_packages(tmpdir): def test_project_structure_after_customized_build_py_packages(tmpdir): source_pkg_dir = os.path.join(TEST_DIR, "example_custom_pkg") - pkg_dir = str(tmpdir) + "/" + "example_custom_pkg" + pkg_dir = f"{str(tmpdir)}/example_custom_pkg" shutil.copytree(source_pkg_dir, pkg_dir) env = copy.copy(os.environ)