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

[FIX] ruff: ignore printf-string-formatting of rule up031 #279

Conversation

sanderlienaerts
Copy link
Contributor

When not using Ruff, pre-commit prevents pyupgrade from replacing printf with str.format() (#49).

Using Ruff this rule is not being ignored. This commit modifies the Ruff configuration adding an ignore rule for UP031.

When not using Ruff, pre-commit prevents pyupgrade from replacing printf with str.format() (OCA#49). Using Ruff this rule is not being ignored. This commit modifies the Ruff configuration adding an ignore rule for UP031.
@pedrobaeza
Copy link
Member

In which cases ruff is not used?

@sanderlienaerts
Copy link
Contributor Author

sanderlienaerts commented Oct 11, 2024

In which cases ruff is not used?

Ruff is not being used in version < 14 or when use_ruff is set to False in Copier by the user. It is also False by default if the version is < 17.

@sbidoul
Copy link
Member

sbidoul commented Oct 12, 2024

I think we should not disable UP031.

If my memory is correct, using .format is only a risk for translatable strings, and that is caught by pylint Odoo.
And in Odoo the best pattern for translatable strings is _("aaa %s bbb %s", 1, 2), which is not handled by UP031.

In other cases, that rule is useful, because f-strings are generally more readable that printf style.

@sanderlienaerts
Copy link
Contributor Author

If my memory is correct, using .format is only a risk for translatable strings, and that is caught by pylint Odoo. And in Odoo the best pattern for translatable strings is _("aaa %s bbb %s", 1, 2), which is not handled by UP031.

I have just tested this on the pre-commit config, confirming that this is the current working behaviour. So since formatting conventions for translatable strings are upheld, I will close the PR. Thanks for your feedback.

@sanderlienaerts sanderlienaerts deleted the cf-ruff-exclude-up031-printf-string-formatting branch November 4, 2024 12:39
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.

3 participants