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 ruff/pyupgrade rules (UP) #786
base: main
Are you sure you want to change the base?
Conversation
251929a
to
434fdb5
Compare
UP030 Use implicit references for positional format fields
UP031 Use format specifiers instead of percent format
ee69be5
to
24efab4
Compare
UP032 Use f-string instead of `format` call
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 don't think UP032 is a good rule to be enforcing as-is, at least not without changing the surrounding logic to keep it valid.
tasks/check.py
Outdated
"Projects with Differing Latest Version: {}/{} ({:.2%})".format( | ||
len(differing_latest_versions), | ||
len(data), | ||
len(differing_latest_versions) / len(data), | ||
) | ||
f"Projects with Differing Latest Version: {len(differing_latest_versions)}/" | ||
f"{len(data)} ({len(differing_latest_versions) / len(data):.2%})" |
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 newer form is strictly less readable IMO.
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 can understand why you prefer the first form. Add a noqa:
or disable UP032
globally?
I gave noqa:
a try.
tests/test_requirements.py
Outdated
@@ -118,7 +118,7 @@ def test_basic_valid_requirement_parsing( | |||
parts = [name] | |||
if extras: | |||
parts.append("[") | |||
parts.append("{ws},{ws}".format(ws=whitespace).join(sorted(extras))) | |||
parts.append(f"{whitespace},{whitespace}".join(sorted(extras))) |
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.
This makes this specific spot inconsistent with the rest of the test, which I don't like much.
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 see no easy alternative other than disabling UP032
? Locally with a noqa:
? Globally?
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.
But then the extras
case is different from the rest.
src/packaging/tags.py
Outdated
yield "macosx_{major}_{minor}_{binary_format}".format( | ||
major=compat_version[0], | ||
minor=compat_version[1], | ||
binary_format=binary_format, | ||
) | ||
yield f"macosx_{compat_version[0]}_{compat_version[1]}_{binary_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.
The newer form is strictly less readable IMO -- the named arguments for the template string were useful.
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.
Would you like to disable UP032
? Or perhaps change to the following?
major=compat_version[0]
minor=compat_version[1]
yield f"macosx_{major}_{minor}_{binary_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.
I tried a variant of the second suggestion, which results in more consistent code — and perhaps more readable.
src/packaging/tags.py
Outdated
yield "macosx_{major}_{minor}_{binary_format}".format( | ||
major=compat_version[0], | ||
minor=compat_version[1], | ||
binary_format=binary_format, | ||
yield ( | ||
f"macosx_{compat_version[0]}_{compat_version[1]}" | ||
f"_{binary_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.
Same as above.
src/packaging/tags.py
Outdated
yield "macosx_{major}_{minor}_{binary_format}".format( | ||
major=major_version, minor=0, binary_format=binary_format | ||
) | ||
yield f"macosx_{major_version}_0_{binary_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.
Same as above.
src/packaging/tags.py
Outdated
yield "macosx_{major}_{minor}_{binary_format}".format( | ||
major=10, minor=minor_version, binary_format=binary_format | ||
) | ||
yield f"macosx_10_{minor_version}_{binary_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.
Same as above.
58e6036
to
e7b3222
Compare
https://docs.astral.sh/ruff/rules/format-literals/
https://docs.astral.sh/ruff/rules/printf-string-formatting/
https://docs.astral.sh/ruff/rules/f-string/