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

Implement flake8-use-fstring #2097

Closed
Secrus opened this issue Jan 22, 2023 · 4 comments
Closed

Implement flake8-use-fstring #2097

Secrus opened this issue Jan 22, 2023 · 4 comments
Labels
plugin Implementing a known but unsupported plugin question Asking for support or clarification

Comments

@Secrus
Copy link
Contributor

Secrus commented Jan 22, 2023

https://github.com/MichaelKim0407/flake8-use-fstring

  • FS001: % formatting is used.

  • FS002: .format formatting is used.

  • FS003: f-string missing prefix (ignored by default).

Config options:
--percent-greedy, --format-greedy

  • Level 0 (default): only report error if the value before % or .format is a string literal.

  • Level 1: report error if a string literal appears before % or .format anywhere in the statement.

  • Level 2: report any usage of % or .format.

@charliermarsh
Copy link
Member

I believe we support FS001 and FS002, at least partially, as UP031 and UP032, which also automatically upgrade % strings to .format strings, and .format strings to f-strings.

(I say "partially", because it doesn't flag every usage of % and .format strings -- it omits some cases depending on formatting.)

@charliermarsh charliermarsh added the plugin Implementing a known but unsupported plugin label Jan 23, 2023
@charliermarsh
Copy link
Member

We could change UP031 and UP032 to always flag those string formatting methods, even if they can't fix them. That'd be one way to close out this issue. But it's a bit of a behavior change for those rules.

@Secrus
Copy link
Contributor Author

Secrus commented Jan 25, 2023

Let me test how it works right now, looking at the rules description, it might actually be enough.

@charliermarsh charliermarsh added the question Asking for support or clarification label Jan 25, 2023
@martinhoyer
Copy link

@charliermarsh Sorry for necro'ing a closed issue - just want to mention that in my recent usage, UP032 did indeed left some .format()s, which are a bit more complex then just already assigned variable(s).
I'm thinking an opt-in option in settings for it to flag them, even though auto-fix is not available could be nice?
Might include comment, like "consider adding helper variable for complex formatting before using it in f-string"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin Implementing a known but unsupported plugin question Asking for support or clarification
Projects
None yet
Development

No branches or pull requests

3 participants