`str-format` for fill and align specifiers
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Feature
The fill and align string format specifiers do not currently have type checking, but are not supported by all types. Specifically, None does not support them.
Pitch
I ran into a bug where an optional type was being passed to string formatting using <. This would succeed most of the time, but error if the value was None:
>>> "{:<2}".format(None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported format string passed to NoneType.__format__
It would be great if mypy would catch this code as a type violation.
I attempted to implement here: https://github.com/python/mypy/pull/18799 but this was more challenging than I anticipated and I am a first time contributor.
Thanks.
Contributor guide
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
Review the attempted implementation in PR #18799 first, then trace mypy's handling of format-specifier type checking for fill and align specifiers. Done means mypy reports an error when an optional value such as None is formatted with an unsupported fill or alignment specifier.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100