Skip to content

Commit 7e7e848

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

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

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:

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:

commitizen/changelog_formats/restructuredtext.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ 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 = "{partial_version}-{matches['prerelease']}"
8181
if matches.get("devrelease"):
82-
partial_version += f"{matches['devrelease']}"
82+
partial_version = "{partial_version}{matches['devrelease']}"
8383
meta.latest_version = partial_version
8484
meta.latest_version_position = index
8585
break

commitizen/changelog_formats/textile.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ 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([version_segment in matches for version_segment in ("major", "minor", "patch")]):
2723
return None
24+
25+
partial_version = (
26+
f"{matches['major']}.{matches['minor']}.{matches['patch']}"
27+
)
2828

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

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

0 commit comments

Comments
 (0)