Skip to content

Commit 8072d02

Browse files
authored
Use sorted() instead of in-place sorting (#10603)
1 parent 62b5da4 commit 8072d02

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

pylint/checkers/symilar.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,7 @@ def _compute_sims(self) -> list[tuple[int, set[LinesChunkLimits_T]]]:
430430
cpls: set[LinesChunkLimits_T]
431431
for cpls in ensembles:
432432
sims.append((num, cpls))
433-
sims.sort(reverse=True)
434-
return sims
433+
return sorted(sims, reverse=True)
435434

436435
def _display_sims(
437436
self, similarities: list[tuple[int, set[LinesChunkLimits_T]]]

pylint/message/message_id_store.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,23 +102,21 @@ def check_msgid_and_symbol(self, msgid: str, symbol: str) -> None:
102102
@staticmethod
103103
def _raise_duplicate_symbol(msgid: str, symbol: str, other_symbol: str) -> NoReturn:
104104
"""Raise an error when a symbol is duplicated."""
105-
symbols = [symbol, other_symbol]
106-
symbols.sort()
107-
error_message = f"Message id '{msgid}' cannot have both "
108-
error_message += f"'{symbols[0]}' and '{symbols[1]}' as symbolic name."
109-
raise InvalidMessageError(error_message)
105+
symbol_a, symbol_b = sorted([symbol, other_symbol])
106+
raise InvalidMessageError(
107+
f"Message id '{msgid}' cannot have both "
108+
f"'{symbol_a}' and '{symbol_b}' as symbolic name."
109+
)
110110

111111
@staticmethod
112112
def _raise_duplicate_msgid(symbol: str, msgid: str, other_msgid: str) -> NoReturn:
113113
"""Raise an error when a msgid is duplicated."""
114-
msgids = [msgid, other_msgid]
115-
msgids.sort()
116-
error_message = (
114+
msgid_a, msgid_b = sorted([msgid, other_msgid])
115+
raise InvalidMessageError(
117116
f"Message symbol '{symbol}' cannot be used for "
118-
f"'{msgids[0]}' and '{msgids[1]}' at the same time."
117+
f"'{msgid_a}' and '{msgid_b}' at the same time."
119118
f" If you're creating an 'old_names' use 'old-{symbol}' as the old symbol."
120119
)
121-
raise InvalidMessageError(error_message)
122120

123121
def get_active_msgids(self, msgid_or_symbol: str) -> list[str]:
124122
"""Return msgids but the input can be a symbol.

0 commit comments

Comments
 (0)