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

Apply ruff/pyupgrade rules (UP) #786

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

DimitriPapadopoulos
Copy link
Contributor

@DimitriPapadopoulos DimitriPapadopoulos commented Mar 10, 2024

UP030 Use implicit references for positional format fields

https://docs.astral.sh/ruff/rules/format-literals/

UP031 Use format specifiers instead of percent format

https://docs.astral.sh/ruff/rules/printf-string-formatting/

UP032 Use f-string instead of `format` call

https://docs.astral.sh/ruff/rules/f-string/

	UP030 Use implicit references for positional format fields
	UP031 Use format specifiers instead of percent format
@DimitriPapadopoulos DimitriPapadopoulos changed the title Fix ruff/pyupgrade issues (UP) Apply ruff/pyupgrade rules (UP) May 8, 2024
	UP032 Use f-string instead of `format` call
Copy link
Member

@pradyunsg pradyunsg left a 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
Comment on lines 136 to 127
"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%})"
Copy link
Member

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.

Copy link
Contributor Author

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.

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

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.

Copy link
Contributor Author

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?

Copy link
Contributor Author

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.

Comment on lines 479 to 473
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}"
Copy link
Member

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.

Copy link
Contributor Author

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}"

Copy link
Contributor Author

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.

Comment on lines 470 to 467
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}"
Copy link
Member

Choose a reason for hiding this comment

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

Same as above.

Comment on lines 453 to 450
yield "macosx_{major}_{minor}_{binary_format}".format(
major=major_version, minor=0, binary_format=binary_format
)
yield f"macosx_{major_version}_0_{binary_format}"
Copy link
Member

Choose a reason for hiding this comment

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

Same as above.

Comment on lines 442 to 441
yield "macosx_{major}_{minor}_{binary_format}".format(
major=10, minor=minor_version, binary_format=binary_format
)
yield f"macosx_10_{minor_version}_{binary_format}"
Copy link
Member

Choose a reason for hiding this comment

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

Same as above.

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.

None yet

2 participants