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

Check for invalid format specifiers #644

Open
asmeurer opened this issue Jun 9, 2021 · 0 comments
Open

Check for invalid format specifiers #644

asmeurer opened this issue Jun 9, 2021 · 0 comments

Comments

@asmeurer
Copy link
Contributor

asmeurer commented Jun 9, 2021

pyflakes does some format specifier checks (#443), but it isn't able to detect invalid format specifiers. For example

f"{x:f.1}"
"{x:f.1}".format(x=1)

are both wrong (the f is supposed to go after the .1). Also the f-string one is a ValueError and is only checked at runtime.

The format specification mini-language is pretty complicated, so this would be useful, but also maybe not easy to implement. For .format strings you can use https://docs.python.org/3/library/string.html#string.Formatter.parse, but for f-strings, there's nothing in the standard library that can tokenize the f-string components (it would be useful if there were). Libraries like pygments and parso can tokenize them, or maybe the tokenizer added in #443 can be extended to handle them.

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

No branches or pull requests

1 participant