Skip to content

Commit a86a28c

Browse files
committed
perf(parser-angular): simplify commit parsing type pre-calculation
1 parent 5b64a38 commit a86a28c

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/semantic_release/commit_parser/angular.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import logging
99
import re
1010
from functools import reduce
11+
from itertools import zip_longest
1112
from re import compile as regexp
1213
from typing import TYPE_CHECKING, Tuple
1314

@@ -71,11 +72,16 @@ class AngularParserOptions(ParserOptions):
7172
default_bump_level: LevelBump = LevelBump.NO_RELEASE
7273

7374
def __post_init__(self) -> None:
74-
self.tag_to_level = {tag: self.default_bump_level for tag in self.allowed_tags}
75-
for tag in self.patch_tags:
76-
self.tag_to_level[tag] = LevelBump.PATCH
77-
for tag in self.minor_tags:
78-
self.tag_to_level[tag] = LevelBump.MINOR
75+
self.tag_to_level: dict[str, LevelBump] = dict(
76+
[
77+
# we have to do a type ignore as zip_longest provides a type that is not specific enough
78+
# for our expected output. Due to the empty second array, we know the first is always longest
79+
# and that means no values in the first entry of the tuples will ever be a LevelBump.
80+
*zip_longest(self.allowed_tags, (), fillvalue=self.default_bump_level), # type: ignore[list-item]
81+
*zip_longest(self.patch_tags, (), fillvalue=LevelBump.PATCH), # type: ignore[list-item]
82+
*zip_longest(self.minor_tags, (), fillvalue=LevelBump.MINOR), # type: ignore[list-item]
83+
]
84+
)
7985

8086

8187
class AngularCommitParser(CommitParser[ParseResult, AngularParserOptions]):

0 commit comments

Comments
 (0)