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

Mypy does not detect redundant keyword arguments in 'str.format()' #11336

Open
AIGeneratedUsername opened this issue Oct 14, 2021 · 1 comment · May be fixed by #11340
Open

Mypy does not detect redundant keyword arguments in 'str.format()' #11336

AIGeneratedUsername opened this issue Oct 14, 2021 · 1 comment · May be fixed by #11340
Labels
bug mypy got something wrong

Comments

@AIGeneratedUsername
Copy link

AIGeneratedUsername commented Oct 14, 2021

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
@AIGeneratedUsername AIGeneratedUsername added the bug mypy got something wrong label Oct 14, 2021
@AIGeneratedUsername AIGeneratedUsername changed the title Mypy does not detect extra keywords in 'str.format()' Mypy does not detect redundant keyword arguments in 'str.format()' Oct 14, 2021
@97littleleaf11
Copy link
Collaborator

This issue could be separate into two fixes:

  • Fix final value inferring
  • Fix last_know_value inferring

@97littleleaf11 97littleleaf11 linked a pull request Oct 15, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants