Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[trailing-comma-tuple] Fix enabling with message control locally when disabled for the file #9609

Conversation

Pierre-Sassoulas
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas commented May 7, 2024

Type of Changes

Type
🐛 Bug fix

Description

Refs #8606, #9620 (follow-up)
Closes #9608

Copy link

codecov bot commented May 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.84%. Comparing base (ce47a62) to head (1eedcbb).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #9609   +/-   ##
=======================================
  Coverage   95.84%   95.84%           
=======================================
  Files         174      174           
  Lines       18897    18904    +7     
=======================================
+ Hits        18112    18119    +7     
  Misses        785      785           
Files Coverage Δ
pylint/checkers/refactoring/refactoring_checker.py 98.27% <100.00%> (+<0.01%) ⬆️
pylint/lint/message_state_handler.py 96.48% <ø> (ø)

... and 2 files with indirect coverage changes

This comment has been minimized.

Copy link
Collaborator

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just saw your comment on the issue. This does indeed not work.

@Pierre-Sassoulas
Copy link
Member Author

Pierre-Sassoulas commented May 7, 2024

Jeez, I wonder why ruff don't have fine grained message control yet 😄 (I did not benchmark this yet, I probably need to test some assumptions about the caching of per line enable vs checking the enable on each token).

@Pierre-Sassoulas Pierre-Sassoulas marked this pull request as ready for review May 7, 2024 21:44
@Pierre-Sassoulas Pierre-Sassoulas marked this pull request as draft May 7, 2024 21:48

This comment has been minimized.

@Pierre-Sassoulas Pierre-Sassoulas force-pushed the is-message-enabled-optimization branch from d1ad751 to 5cd7c05 Compare May 8, 2024 12:44
@Pierre-Sassoulas Pierre-Sassoulas changed the title [performance] Check that 'trailing-comma-tuple' is enabled only once Check that 'trailing-comma-tuple' is enabled less often, and raise 'trailing-comma-tuple' when disabled globally and enabled locally May 8, 2024
@Pierre-Sassoulas Pierre-Sassoulas changed the title Check that 'trailing-comma-tuple' is enabled less often, and raise 'trailing-comma-tuple' when disabled globally and enabled locally [trailing-comma-tuple] Optimize check, fix local enabling when globally disabled May 8, 2024
@Pierre-Sassoulas Pierre-Sassoulas force-pushed the is-message-enabled-optimization branch from 5cd7c05 to 42eff43 Compare May 8, 2024 12:54

This comment has been minimized.

@Pierre-Sassoulas
Copy link
Member Author

Wow, is_message_enabled is seriously misleading. I suggest we rename to is_message_enabled_for_current_file or create an argument for the file which default to current for 3.0 and to None in 4.0, what do you think @DanielNoord ?

This comment has been minimized.

@DanielNoord
Copy link
Collaborator

Hmm, do we know if this actually meaningfully influences performance? Yes calling a function often is bad, but if the effect on performance is negligible than we might not want to overcomplicate our config handling (again).

@Pierre-Sassoulas
Copy link
Member Author

I was thinking about misleadingness rather than performance. {Number of files} calls is not that problematic, but the function name making me lose 2 hours of debug is :D

@Pierre-Sassoulas
Copy link
Member Author

By the way I still don't understand why locally everything work and not in the CI, but I'm short on time atm.

@nickdrozd
Copy link
Collaborator

Does this fix #8201?

This comment has been minimized.

This comment has been minimized.

@jacobtylerwalls
Copy link
Member

Thanks for your work here on this important improvement. I'm wondering what you think about backporting performance improvements. Should we try to keep the patch releases more stable by only backporting bugfixes and not refactors?

@jacobtylerwalls
Copy link
Member

Oh woah, I had it backwards. This is the bugfix. Carry on!

@Pierre-Sassoulas Pierre-Sassoulas force-pushed the is-message-enabled-optimization branch from 2ea3405 to daeab1f Compare May 18, 2024 13:42
@Pierre-Sassoulas
Copy link
Member Author

I can understand the confusion because I'm trying very hard to optimize the bug fix itself 😄

@Pierre-Sassoulas Pierre-Sassoulas marked this pull request as ready for review May 18, 2024 13:43
@Pierre-Sassoulas Pierre-Sassoulas force-pushed the is-message-enabled-optimization branch from daeab1f to 865d57c Compare May 18, 2024 13:45
@Pierre-Sassoulas Pierre-Sassoulas force-pushed the is-message-enabled-optimization branch from 4dd9da9 to 1eedcbb Compare May 18, 2024 13:52
disable=trailing-comma-tuple

[testoptions]
exclude_from_minimal_messages_config=True
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got very confused by that error at first (Didn't see it was a specific automated test that was failing). I chose the fast fix but maybe taking into account the conf file after disabling everything and checking what's expected in the functional test would be better than the current behavior.

@Pierre-Sassoulas Pierre-Sassoulas dismissed DanielNoord’s stale review May 18, 2024 13:55

Was a review on #9620, this MR was repurposed.

@jacobtylerwalls jacobtylerwalls modified the milestones: 3.2.2, 3.2.1 May 18, 2024
# Process tokens and look for 'if' or 'elif'
for index, token in enumerate(tokens):
token_string = token[1]
if (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about factoring this out into a helper method? It's almost 20 lines with comments.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think we need to make this kind of optimization where we do not compute things when a message is disabled easier to use because the faster computation is the one you never do.

If we create an helper then we'd probably want to parametrize "trailing-comma-tuple" / "R1707" so it can be useful elsewhere with other messages (then we should be using the message store to get old name of the message if a message was ever renamed ?). And it adds a call.

We have the "perfect function" for this already with self.linter.is_message_enabled( applied on a line (barring some optimization to do here related to not launching it on each token as they are multiple token per line). It felt very heavy handed in this case so I did something very specific without check for old name / and without exact check of enabling or not.

To be honest I made a lot of assumptions without ever doing a benchmark. One way to keep this clean and dry would be to make the message store better for this use case (token checks, and probably enabled but not absolutely sure it still is?).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, we can merge as is. I wasn't suggesting reusing it elsewhere, I just meant hoisting it out of this current location into a few lines up in the same file.

Copy link
Contributor

🤖 According to the primer, this change has no effect on the checked open source code. 🤖🎉

This comment was generated for commit 1eedcbb

@jacobtylerwalls jacobtylerwalls merged commit 96fad05 into pylint-dev:main May 18, 2024
44 checks passed
github-actions bot pushed a commit that referenced this pull request May 18, 2024
… disabled for the file (#9609)

* [trailing-comma-tuple] Set the confidence to HIGH

* [trailing-comma-tuple] Properly emit when disabled globally and enabled locally

* [trailing-comma-tuple] Handle case with space between 'enable' and '='

(cherry picked from commit 96fad05)
jacobtylerwalls pushed a commit that referenced this pull request May 18, 2024
… disabled for the file (#9609)

* [trailing-comma-tuple] Set the confidence to HIGH

* [trailing-comma-tuple] Properly emit when disabled globally and enabled locally

* [trailing-comma-tuple] Handle case with space between 'enable' and '='

(cherry picked from commit 96fad05)
@Pierre-Sassoulas Pierre-Sassoulas deleted the is-message-enabled-optimization branch May 18, 2024 15:49
jacobtylerwalls pushed a commit that referenced this pull request May 18, 2024
… disabled for the file (#9609) (#9649)

* [trailing-comma-tuple] Set the confidence to HIGH

* [trailing-comma-tuple] Properly emit when disabled globally and enabled locally

* [trailing-comma-tuple] Handle case with space between 'enable' and '='

(cherry picked from commit 96fad05)

Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

R1707 (trailing-comma-tuple) checks perform excessive is_message_enabled calls
4 participants