-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Apply more assorted Pyugrade suggestions #4125
Conversation
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.
Thank you very much @DimitriPapadopoulos.
I will not merge this immediately because I am waiting to see if any other bugfixes are necessary for v69, but I think we can merge the PR soon in the future.
Thank you for looking into this. Would you agree to add the pyupgrade linter once I have finished fixing the issues reported by pyupgrade? |
If @jaraco is OK with that, I think this change would be fine (we will need to prevent/ignore changes in the |
By the way, I don't know how you feel about ruff, but it lets you disable pyupgrade rules, while the original pyupgrade is rather opinionated and does not let you disable any of its rules. |
I think we are already using |
A sample extend-select = [
"UP", # pyupgrade
]
extend-ignore = [
"UP015", # redundant-open-modes, explicit is prefered
]
extend-exclude = [
# Vendored
"**/_vendor",
"setuptools/_distutils",
] |
Doesn't pytest-ruff search its config in |
@jaraco 's previously written opinion on this, which I think will apply just the same to Ruff: #3979 (review)
|
1ead630
to
b2bb9f7
Compare
I have added a I have disabled warnings about string interpolation for now, because the changes are really pervasive. Also, I find f-strings might be less readable when string interpolation involves a complex expression instead of a mere variable. In such cases, I feel keeping |
Let's wait to see if Jason is Ok with the approach. Worst case scenario we can remove the |
Don’t let me be the blocker here.
Normally, I’d like changes like these to be considered at jaraco/skeleton so they can apply to all projects and be kept in sync. The specific effects on this codebase, and configuration specific to this codebase, however, would need to be submitted here. So let’s move forward with this change here and see what implications it has for the general approach.
I’m pleased to see the use of Ruff over pyupgrade. Id also be interested to see Ruff replace black and implement other common formatting/linking like import sorts.
|
@DimitriPapadopoulos, let's merge this PR as it is then (but I will not cutting a release right now, just add the changes to main, I hope that is OK).
If that would allow us to reduce the configuration size for Ruff, I like the idea of temporary variable. I think it is worth to be as streamline as possible. But let's do that in a follow up PR... |
I have started working on this in jaraco/skeleton#99. |
Postponed until we figure out what happened on |
@abravalheri I have noticed that jaraco/skeleton uses the recent jaraco/skeleton/pyproject.toml [tool.black]
skip-string-normalization = true Should I instruct black to leave quotes as they are, as in jaraco/skeleton? On the other hand, this project has already been black'ified with double quotes everywhere. |
I think that setuptools should target to have |
b2bb9f7
to
2fc03cb
Compare
ruff.toml
Outdated
@@ -1,4 +1,3 @@ | |||
[lint] |
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.
Should we just leave the [lint]
section header so it differs less from the skeleton
configuration?
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.
Good catch. I should rather fix the skeleton
configuration as ignore
is part of the Top-level Ruff Settings:
jaraco/skeleton#106
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 think that the ruff
docs are a bit outdated, the main example uses the [lint]
section, and the detailed reference puts them the the global scope... Which is a bit confusing :P
Henry once told me that in the past Ruff docs would use the global config but now they are going towards [lint]
...
In this PR we can see the author referencing the new lint
sections:
- Breaking up "Configuration" into "Configuring Ruff" (for generic configuration), and new Linter- and Formatter-specific sections.
- Updating all example configurations to use [tool.ruff.lint] and [tool.ruff.format].
So that sounds like it is the most up-to-date thing to do (at least until the next release 😅)
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.
They are going towards lint
for all options that are related to lint
, that's for sure. However, ignore
applies to both lint
and format
. At least that's my understanding.
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.
Perfect, we got a definitive answer from the maintainers: astral-sh/ruff#8297 (reply in thread)
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'll put back [lint]
.
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.
Done. But note this requires to duplicate extend-exclude
, both under [lint]
and [format]
.
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.
Thank you very much @DimitriPapadopoulos.
Yeah, not ideal. But I guess it is good to go with Ruff maintainer's recommendation.
This is a suggestion from pyupgrade: /~https://github.com/asottile/pyupgrade#yield--yield-from
In Python 3, io.open() is an alias for the builtin open() function. https://docs.python.org/3/library/io.html#io.open This is a suggestion from pyupgrade: /~https://github.com/asottile/pyupgrade#open-alias
See PEP 3135: https://peps.python.org/pep-3135/ This is a suggestion from pyupgrade: /~https://github.com/asottile/pyupgrade#super-calls
Fixed by running `ruff --select UP018 --fix .`: UP018 [*] Unnecessary `str` call (rewrite as a literal) Original suggestions from pyupgrade: /~https://github.com/asottile/pyupgrade#forced-strnative-literals
This is an alias for the built-in OSError exception: https://docs.python.org/3/library/os.html#os.error Fixed by running `ruff --select UP024 --fix .`: UP024 [*] Replace aliased errors with `OSError`
In Python ≥ 3.7, `capture_output` can be used instead of `stdout=PIPE` / `stderr=PIPE`. Fixed by running `ruff --select UP022 --fix --unsafe-fixes .`: UP022 Sending `stdout` and `stderr` to `PIPE` is deprecated, use `capture_output`
Fixed by running `ruff --select UP034 --fix .`: UP034 [*] Avoid extraneous parentheses
In Python 3, the source encodign is implict, UTF-8 by default. This is a suggestion from pyupgrade: /~https://github.com/asottile/pyupgrade#-coding--comment Fixed by running `ruff --select UP009 --fix .`: UP009 [*] UTF-8 encoding declaration is unnecessary
This is a suggestion from pyupgrade: /~https://github.com/asottile/pyupgrade#encode-to-bytes-literals Fixed by running `ruff --select UP012 --fix .`: UP012 [*] Unnecessary call to `encode` as UTF-8
Fixed by running `ruff --select UP027 --fix .`: UP027 [*] Replace unpacked list comprehension with a generator expression
I just squashed the first and last commit together because I want to avoid as much as I can future git conflicts. |
Thank you very much for the contribution! |
Summary of changes
Apply more suggestions from pyupgrade.
Pull Request Checklist
newsfragments/
.(See documentation for details)