Skip to content

Commit

Permalink
[performance] Check that 'trailing-comma-tuple' is enabled only once
Browse files Browse the repository at this point in the history
Performance analysis by correctmost

Refs pylint-dev#8606 (follow-up)
Closes pylint-dev#9608
  • Loading branch information
Pierre-Sassoulas committed May 8, 2024
1 parent 7521eb1 commit a155af7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 4 additions & 0 deletions doc/whatsnew/fragments/9608.performance
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
An internal check for ``trailing-comma-tuple`` being globally enabled or not is now
done once instead of once for each token.

Refs #9608.
9 changes: 6 additions & 3 deletions pylint/checkers/refactoring/refactoring_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,9 @@ def open(self) -> None:
self._suggest_join_with_non_empty_separator = (
self.linter.config.suggest_join_with_non_empty_separator
)
self.trailing_comma_tuple_enabled_globally = self.linter.is_message_enabled(
"trailing-comma-tuple"
)

@cached_property
def _dummy_rgx(self) -> Pattern[str]:
Expand Down Expand Up @@ -659,9 +662,9 @@ def process_tokens(self, tokens: list[tokenize.TokenInfo]) -> None:
# token[2] is the actual position and also is
# reported by IronPython.
self._elifs.extend([token[2], tokens[index + 1][2]])
elif self.linter.is_message_enabled(
"trailing-comma-tuple"
) and _is_trailing_comma(tokens, index):
elif self.trailing_comma_tuple_enabled_globally and _is_trailing_comma(
tokens, index
):
self.add_message("trailing-comma-tuple", line=token.start[0])

@utils.only_required_for_messages("consider-using-with")
Expand Down

0 comments on commit a155af7

Please sign in to comment.