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

Adopt the SIM rules #4156

Merged
merged 2 commits into from
Jan 13, 2025
Merged

Adopt the SIM rules #4156

merged 2 commits into from
Jan 13, 2025

Conversation

vivodi
Copy link
Contributor

@vivodi vivodi commented Jan 11, 2025

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

@vivodi
Copy link
Contributor Author

vivodi commented Jan 11, 2025

This is ready for review. @gazpachoking

Copy link
Member

@gazpachoking gazpachoking left a 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)
Copy link
Member

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.

Copy link
Contributor Author

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.

flexget/components/emby/api_emby.py Outdated Show resolved Hide resolved
@vivodi
Copy link
Contributor Author

vivodi commented Jan 12, 2025

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.

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.

@gazpachoking
Copy link
Member

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.

@vivodi
Copy link
Contributor Author

vivodi commented Jan 13, 2025

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.

@gazpachoking gazpachoking merged commit b9a8aff into Flexget:develop Jan 13, 2025
20 checks passed
@vivodi vivodi deleted the e501 branch January 14, 2025 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants