Skip to content

Commit d5dcf4d

Browse files
grahamharLee-W
andcommitted
refactor: Use format strings
Co-authored-by: Wei Lee <[email protected]>
1 parent c19cd1d commit d5dcf4d

File tree

5 files changed

+23
-14
lines changed

5 files changed

+23
-14
lines changed

Diff for: commitizen/changelog_formats/asciidoc.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ def parse_version_from_title(self, line: str) -> str | None:
2727
return None
2828

2929
if partial_matches.get("prerelease"):
30-
partial_version += f"-{partial_matches['prerelease']}"
30+
partial_version = f"{partial_version}-{partial_matches['prerelease']}"
3131
if partial_matches.get("devrelease"):
32-
partial_version += f"{partial_matches['devrelease']}"
32+
partial_version = f"{partial_version}{partial_matches['devrelease']}"
3333
return partial_version
3434

3535
def parse_title_level(self, line: str) -> int | None:

Diff for: commitizen/changelog_formats/markdown.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ def parse_version_from_title(self, line: str) -> str | None:
3030
return None
3131

3232
if matches.get("prerelease"):
33-
partial_version += f"-{matches['prerelease']}"
33+
partial_version = f"{partial_version}-{matches['prerelease']}"
3434
if matches.get("devrelease"):
35-
partial_version += f"{matches['devrelease']}"
35+
partial_version = f"{partial_version}{matches['devrelease']}"
3636
return partial_version
3737

3838
def parse_title_level(self, line: str) -> int | None:

Diff for: commitizen/changelog_formats/restructuredtext.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,13 @@ def get_metadata_from_file(self, file: IO[Any]) -> Metadata:
7777
f"{matches['major']}.{matches['minor']}.{matches['patch']}"
7878
)
7979
if matches.get("prerelease"):
80-
partial_version += f"-{matches['prerelease']}"
80+
partial_version = (
81+
f"{partial_version}-{matches['prerelease']}"
82+
)
8183
if matches.get("devrelease"):
82-
partial_version += f"{matches['devrelease']}"
84+
partial_version = (
85+
f"{partial_version}{matches['devrelease']}"
86+
)
8387
meta.latest_version = partial_version
8488
meta.latest_version_position = index
8589
break

Diff for: commitizen/changelog_formats/textile.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,20 @@ def parse_version_from_title(self, line: str) -> str | None:
1919
if "version" in m.groupdict():
2020
return m.group("version")
2121
matches = m.groupdict()
22-
try:
23-
partial_version = (
24-
f"{matches['major']}.{matches['minor']}.{matches['patch']}"
25-
)
26-
except KeyError:
22+
if not all(
23+
[
24+
version_segment in matches
25+
for version_segment in ("major", "minor", "patch")
26+
]
27+
):
2728
return None
2829

30+
partial_version = f"{matches['major']}.{matches['minor']}.{matches['patch']}"
31+
2932
if matches.get("prerelease"):
30-
partial_version += f"-{matches['prerelease']}"
33+
partial_version = f"{partial_version}-{matches['prerelease']}"
3134
if matches.get("devrelease"):
32-
partial_version += f"{matches['devrelease']}"
35+
partial_version = f"{partial_version}{matches['devrelease']}"
3336
return partial_version
3437

3538
def parse_title_level(self, line: str) -> int | None:

Diff for: commitizen/defaults.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ class Settings(TypedDict, total=False):
135135
bump_message = "bump: version $current_version → $new_version"
136136

137137

138-
def get_tag_regexes(version_regex: str) -> dict[str | Any, str | Any]:
138+
def get_tag_regexes(
139+
version_regex: str,
140+
) -> dict[str, str]:
139141
return {
140142
"$version": version_regex,
141143
"$major": r"(?P<major>\d+)",

0 commit comments

Comments
 (0)