Skip to content

Inconsistent result when using StrEnum in f-string #126299

@cappuddono

Description

@cappuddono

Bug report

Bug description:

I define a subclass of StrEnum, and use it in a f-string:

class FruitEnum(StrEnum):
    APPLE = 'apple'

print(f'Example1: {FruitEnum.APPLE}')
# Example1: apple
print(f'Example2: {FruitEnum.APPLE=}')
# Example2: FruitEnum.APPLE=<FruitEnum.APPLE: 'apple'>

The behaviour of printing StrEnum members in f-strings is different. This seems not intuitive. Is this a bug?

CPython versions tested on:

3.12

Operating systems tested on:

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions