@@ -88,18 +88,22 @@ class TagRules:
88
88
ignored_tag_formats : Sequence [str ] = field (default_factory = list )
89
89
merge_prereleases : bool = False
90
90
91
+ @cached_property
92
+ def tag_formats (self ) -> tuple [str , ...]:
93
+ return tuple (self .tag_format , * self .legacy_tag_formats )
94
+
91
95
@cached_property
92
96
def version_regexes (self ) -> list [re .Pattern ]:
93
97
"""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 ]
97
99
98
100
@cached_property
99
101
def ignored_regexes (self ) -> list [re .Pattern ]:
100
102
"""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
+ ]
103
107
104
108
def _format_regex (self , tag_pattern : str , star : bool = False ) -> str :
105
109
"""
@@ -240,10 +244,7 @@ def find_tag_for(
240
244
) -> GitTag | None :
241
245
"""Find the first matching tag for a given version."""
242
246
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 )
247
248
candidates = [t for t in tags if t .name in possible_tags ]
248
249
if len (candidates ) > 1 :
249
250
warnings .warn (
0 commit comments