-
Notifications
You must be signed in to change notification settings - Fork 473
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
Adopt the SIM
rules
#4156
Adopt the SIM
rules
#4156
Conversation
This is ready for review. @gazpachoking |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm mostly fine with this, just a little worried about the amount of changes for the sake of code rules. If they are safe auto fixes, I'm good with it, but I'm a little nervous about manual ones since this is too many changes to manually vet.
"ISC001", # Ruff recommends disabling this when using the ruff formatter | ||
"PLE1205", # Thinks we are using stdlib logging rather than loguru | ||
"RUF001", # Some of these ambiguous unicode are in tests on purpose | ||
"E501", # TODO: enable this rule (requires a lot of manual work) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with just leaving things up to the formatter. I don't think we should enable this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Ruff formatter cannot wrap very long strings, docstrings, and comments. With the E501 rule enabled, you can see that many strings, docstrings, and comments exceed the maximum line length and need to be handled manually. This is an issue with Ruff: astral-sh/ruff#7414.
Since it's difficult to determine the best line break position for automatic fixing, and future versions of Ruff are unlikely to provide an automatic fix for this, I think we should enable the E501 rule.
I understand your concern. While some of these changes aren't automatic fixes, I’ve been very careful when making manual adjustments, and I’ll double-check everything to ensure nothing is missed. I'll make sure the changes are safe and properly handled. |
Aside from the one other note I just added I'm okay with this. I think I would have preferred it broken into multiple PRs, one with only ruff made safe autofixes, then a separate one with manual fixes and enabling the rules. (Don't worry about that now though.) That would have made it a bit easier to give extra scrutiny to the manual ones. |
Thank you for carefully reviewing my PR. If there are similar PRs in the future, I will split them into two as per your request. |
Motivation for changes:
Adopting the SIM rules improves Python code by encouraging simpler, more readable, and maintainable code. It identifies overly complex patterns, redundant conditions, and opportunities for refactoring. This reduces cognitive load, promotes Pythonic practices, and enforces consistent coding styles across a project. Simplifying code also leads to fewer bugs, easier debugging, and faster code reviews.
https://docs.astral.sh/ruff/rules/#flake8-simplify-sim