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

Inconsistent result when using StrEnum in f-string #126299

Closed
cappuddono opened this issue Nov 1, 2024 · 1 comment
Closed

Inconsistent result when using StrEnum in f-string #126299

cappuddono opened this issue Nov 1, 2024 · 1 comment

Comments

@cappuddono
Copy link

cappuddono commented Nov 1, 2024

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

@cappuddono cappuddono added the type-bug An unexpected behavior, bug, or error label Nov 1, 2024
@skirpichev
Copy link
Member

Docs says: When the equal sign '=' is provided, the output will have the expression text, the '=' and the evaluated value ... By default, the '=' causes the repr() of the expression to be provided, unless there is a format specified.

So, you get repr output on rhs in the second case. That can be illustrated on simpler example:

>>> s = "xxx"
>>> print(f'{s}')
xxx
>>> print(f'{s=}')
s='xxx'

@skirpichev skirpichev closed this as not planned Won't fix, can't repro, duplicate, stale Nov 1, 2024
@Eclips4 Eclips4 removed the type-bug An unexpected behavior, bug, or error label Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants