Skip to content

Commit 6e45258

Browse files
[performance] Check that 'trailing-comma-tuple' is enabled only once
Performance analysis by correctmost Refs #8606 (follow-up) Closes #9608
1 parent 7521eb1 commit 6e45258

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
An internal check for ``trailing-comma-tuple`` being enabled or not is now done once instead of once for each token.
2+
3+
Refs #9608.

pylint/checkers/refactoring/refactoring_checker.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,9 @@ def open(self) -> None:
550550
self._suggest_join_with_non_empty_separator = (
551551
self.linter.config.suggest_join_with_non_empty_separator
552552
)
553+
self.trailing_comma_tuple_enabled = self.linter.is_message_enabled(
554+
"trailing-comma-tuple"
555+
)
553556

554557
@cached_property
555558
def _dummy_rgx(self) -> Pattern[str]:
@@ -659,9 +662,9 @@ def process_tokens(self, tokens: list[tokenize.TokenInfo]) -> None:
659662
# token[2] is the actual position and also is
660663
# reported by IronPython.
661664
self._elifs.extend([token[2], tokens[index + 1][2]])
662-
elif self.linter.is_message_enabled(
663-
"trailing-comma-tuple"
664-
) and _is_trailing_comma(tokens, index):
665+
elif self.trailing_comma_tuple_enabled and _is_trailing_comma(
666+
tokens, index
667+
):
665668
self.add_message("trailing-comma-tuple", line=token.start[0])
666669

667670
@utils.only_required_for_messages("consider-using-with")

0 commit comments

Comments
 (0)