Skip to content

Commit 0a9a092

Browse files
committed
refactor(TagRules): extract tag_formats property and simplify list comprehension
1 parent fb04e28 commit 0a9a092

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

commitizen/tags.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,22 @@ class TagRules:
8888
ignored_tag_formats: Sequence[str] = field(default_factory=list)
8989
merge_prereleases: bool = False
9090

91+
@cached_property
92+
def tag_formats(self) -> tuple[str, ...]:
93+
return tuple(self.tag_format, *self.legacy_tag_formats)
94+
9195
@cached_property
9296
def version_regexes(self) -> list[re.Pattern]:
9397
"""Regexes for all legit tag formats, current and legacy"""
94-
tag_formats = [self.tag_format, *self.legacy_tag_formats]
95-
regexes = (self._format_regex(p) for p in tag_formats)
96-
return [re.compile(r) for r in regexes]
98+
return [re.compile(self._format_regex(f)) for f in self.tag_formats]
9799

98100
@cached_property
99101
def ignored_regexes(self) -> list[re.Pattern]:
100102
"""Regexes for known but ignored tag formats"""
101-
regexes = (self._format_regex(p, star=True) for p in self.ignored_tag_formats)
102-
return [re.compile(r) for r in regexes]
103+
return [
104+
re.compile(self._format_regex(f, star=True))
105+
for f in self.ignored_tag_formats
106+
]
103107

104108
def _format_regex(self, tag_pattern: str, star: bool = False) -> str:
105109
"""
@@ -240,10 +244,7 @@ def find_tag_for(
240244
) -> GitTag | None:
241245
"""Find the first matching tag for a given version."""
242246
version = self.scheme(version) if isinstance(version, str) else version
243-
possible_tags = set(
244-
self.normalize_tag(version, f)
245-
for f in (self.tag_format, *self.legacy_tag_formats)
246-
)
247+
possible_tags = set(self.normalize_tag(version, f) for f in self.tag_formats)
247248
candidates = [t for t in tags if t.name in possible_tags]
248249
if len(candidates) > 1:
249250
warnings.warn(

0 commit comments

Comments
 (0)