Skip to content

Commit ab7d759

Browse files
author
Sourcery AI
committed
'Refactored by Sourcery'
1 parent 1b6fd0c commit ab7d759

File tree

4 files changed

+15
-23
lines changed

4 files changed

+15
-23
lines changed

src/unasync/__init__.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,14 @@ def _match(self, filepath):
5757
if len_from_segments > len(file_segments):
5858
return False
5959

60-
for i in range(len(file_segments) - len_from_segments + 1):
61-
if file_segments[i : i + len_from_segments] == from_segments:
62-
return len_from_segments, i
63-
64-
return False
60+
return next(
61+
(
62+
(len_from_segments, i)
63+
for i in range(len(file_segments) - len_from_segments + 1)
64+
if file_segments[i : i + len_from_segments] == from_segments
65+
),
66+
False,
67+
)
6568

6669
def _unasync_file(self, filepath):
6770
with open(filepath, "rb") as f:
@@ -105,9 +108,8 @@ def _unasync_tokens(self, tokens):
105108
def _unasync_name(self, name):
106109
if name in self.token_replacements:
107110
return self.token_replacements[name]
108-
# Convert classes prefixed with 'Async' into 'Sync'
109111
elif len(name) > 5 and name.startswith("Async") and name[5].isupper():
110-
return "Sync" + name[5:]
112+
return f"Sync{name[5:]}"
111113
return name
112114

113115

tests/data/async/simple.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ def __init__(self, a, b):
55
self.s = "UTF-8: ❄"
66

77
async def get_a_b(self):
8-
# fmt: off
9-
s = "a is %s b is %s" % \
10-
(self.a,
11-
self.b)
12-
# fmt: on
13-
return s
8+
return f"a is {self.a} b is {self.b}"
149

1510
async def f(self):
1611
return await 1

tests/data/sync/simple.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ def __init__(self, a, b):
55
self.s = "UTF-8: ❄"
66

77
def get_a_b(self):
8-
# fmt: off
9-
s = "a is %s b is %s" % \
10-
(self.a,
11-
self.b)
12-
# fmt: on
13-
return s
8+
return f"a is {self.a} b is {self.b}"
149

1510
def f(self):
1611
return 1

tests/test_unasync.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def test_unasync_files(tmpdir):
6666
def test_build_py_modules(tmpdir):
6767

6868
source_modules_dir = os.path.join(TEST_DIR, "example_mod")
69-
mod_dir = str(tmpdir) + "/" + "example_mod"
69+
mod_dir = f"{str(tmpdir)}/example_mod"
7070
shutil.copytree(source_modules_dir, mod_dir)
7171

7272
env = copy.copy(os.environ)
@@ -86,7 +86,7 @@ def test_build_py_modules(tmpdir):
8686
def test_build_py_packages(tmpdir):
8787

8888
source_pkg_dir = os.path.join(TEST_DIR, "example_pkg")
89-
pkg_dir = str(tmpdir) + "/" + "example_pkg"
89+
pkg_dir = f"{str(tmpdir)}/example_pkg"
9090
shutil.copytree(source_pkg_dir, pkg_dir)
9191

9292
env = copy.copy(os.environ)
@@ -103,7 +103,7 @@ def test_build_py_packages(tmpdir):
103103
def test_project_structure_after_build_py_packages(tmpdir):
104104

105105
source_pkg_dir = os.path.join(TEST_DIR, "example_pkg")
106-
pkg_dir = str(tmpdir) + "/" + "example_pkg"
106+
pkg_dir = f"{str(tmpdir)}/example_pkg"
107107
shutil.copytree(source_pkg_dir, pkg_dir)
108108

109109
env = copy.copy(os.environ)
@@ -123,7 +123,7 @@ def test_project_structure_after_build_py_packages(tmpdir):
123123
def test_project_structure_after_customized_build_py_packages(tmpdir):
124124

125125
source_pkg_dir = os.path.join(TEST_DIR, "example_custom_pkg")
126-
pkg_dir = str(tmpdir) + "/" + "example_custom_pkg"
126+
pkg_dir = f"{str(tmpdir)}/example_custom_pkg"
127127
shutil.copytree(source_pkg_dir, pkg_dir)
128128

129129
env = copy.copy(os.environ)

0 commit comments

Comments
 (0)