Skip to content

False positive case of "Not all arguments converted during string formatting" #15269

@jfcherng

Description

@jfcherng

Bug Report

Using StrEnum's str.format without via an intermedium varible makes mypy unhappy.

To Reproduce

test.py:

from enum import StrEnum


class Animal(StrEnum):
    DOG = "dog: {name}"


dog = Animal.DOG
print(dog.format(name="Goffy"))  # mypy happy

print(Animal.DOG.format(name="Goffy"))  # mypy unhappy

An alternative snippet for Python < 3.11:

from enum import Enum


class Animal(str, Enum):
    DOG = "dog: {name}"


dog = Animal.DOG
print(dog.format(name="Goffy"))  # mypy happy

print(Animal.DOG.format(name="Goffy"))  # mypy unhappy

Expected Behavior

No error.

Actual Behavior

test.py:11: error: Not all arguments converted during string formatting  [str-format]

Your Environment

  • Mypy version used: 1.7.0
  • Mypy command-line flags: Literally none. (i.e., $ mypy test.py)
  • Mypy configuration options from mypy.ini (and other config files): None.
  • Python version used: 3.12.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions