Check for invalid format specifiers
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.5k
- Forks
- 190
- Avg merge
- 8m
- Merged PRs (30d)
- 13
Description
pyflakes does some format specifier checks (https://github.com/PyCQA/pyflakes/pull/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 https://github.com/PyCQA/pyflakes/pull/443 can be extended to handle them.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the tokenizer added in PyCQA/pyflakes#443 and Python's string.Formatter.parse documentation for .format strings. Compare that approach with the f-string tokenization options mentioned, including pygments and parso. Done means invalid format specifiers such as f.1 are detected in both .format strings and f-strings.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100