Mypy does not detect redundant keyword arguments in 'str.format()'
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
To Reproduce
DOES NOT DETECT
from typing import Final
spam: Final[str] = "spam: {eggs}"
spam_eggs = spam.format(eggs="EGGS", foo="bar")
DOES NOT DETECT
from typing import Final
spam: str = "spam: {eggs}"
spam_eggs = spam.format(eggs="EGGS", foo="bar")
DOES NOT DETECT
spam = "spam: {eggs}"
spam_eggs = spam.format(eggs="EGGS", foo="bar")
DETECTS error: Not all arguments converted during string formatting [str-format]
from typing import Final
spam: Final = "spam: {eggs}"
spam_eggs = spam.format(eggs="EGGS", foo="bar")
Expected Behavior
Always detect redundant keys in the 'format()' and raise an appropriate error.
Actual Behavior
Redundant keys in the 'format()' are detected only when I use Final and only when the Final is without arguments.
Your Environment
- Mypy version used: 0.910
- Python version used: 3.9
- Operating system and version: Lubuntu 20.04
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
Start by running the four examples from the issue with mypy 0.910 and compare which annotations change the result. Trace the string-format checking entry point to determine why redundant keyword arguments are recognized only for an unparameterized Final. Done means the expected error is reported consistently for all shown examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100