Skip to content

Commit a9cd957

Browse files
bearomorphismLee-W
authored andcommitted
perf(bump): avoid unnecessary list construction and rename variable to avoid confusion
1 parent e5452e7 commit a9cd957

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

‎commitizen/bump.py‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
importos
44
importre
55
fromcollectionsimportOrderedDict
6+
fromcollections.abcimportIterable
67
fromglobimportiglob
78
fromloggingimportgetLogger
89
fromstringimportTemplate
@@ -61,7 +62,7 @@ def find_increment(
6162
defupdate_version_in_files(
6263
current_version: str,
6364
new_version: str,
64-
files: list[str],
65+
files: Iterable[str],
6566
*,
6667
check_consistency: bool=False,
6768
encoding: str=ENCODING,
@@ -99,21 +100,22 @@ def update_version_in_files(
99100
returnupdated
100101

101102

102-
def_files_and_regexes(patterns: list[str], version: str) ->list[tuple[str, str]]:
103+
def_files_and_regexes(patterns: Iterable[str], version: str) ->list[tuple[str, str]]:
103104
"""
104105
Resolve all distinct files with their regexp from a list of glob patterns with optional regexp
105106
"""
106-
out: list[tuple[str, str]] =[]
107+
out: set[tuple[str, str]] =set()
107108
forpatterninpatterns:
108109
drive, tail=os.path.splitdrive(pattern)
109110
path, _, regex=tail.partition(":")
110111
filepath=drive+path
111112
ifnotregex:
112113
regex=re.escape(version)
113114

114-
forpathiniglob(filepath):
115-
out.append((path, regex))
116-
returnsorted(list(set(out)))
115+
forfileiniglob(filepath):
116+
out.add((file, regex))
117+
118+
returnsorted(out)
117119

118120

119121
def_bump_with_regex(

0 commit comments

Comments
(0)