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

Not accurate when outputting an error during byte formatting for the 'i' flag, the 'd' flag is output, which can be misleading #130928

Open
ApostolFet opened this issue Mar 6, 2025 · 1 comment
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@ApostolFet
Copy link
Contributor

ApostolFet commented Mar 6, 2025

Bug report

Bug description:

Code for demonstration:

>>> b"%i" % "str"
Traceback (most recent call last):
  File "<python-input-0>", line 1, in <module>
    b"%i" % "str"
    ~~~~~~^~~~~~~
TypeError: %d format: a real number is required, not str

Expected error message text:

TypeError: %i format: a real number is required, not str

Also for strings this message is output correctly:

>>> "%i" % "str"
Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    "%i" % "str"
    ~~~~~^~~~~~~
TypeError: %i format: a real number is required, not str

I would like to send a PR to fix this.

CPython versions tested on:

3.12, 3.13, 3.14, CPython main branch

Operating systems tested on:

Linux

Linked PRs

@ApostolFet ApostolFet added the type-bug An unexpected behavior, bug, or error label Mar 6, 2025
@sobolevn sobolevn added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Mar 6, 2025
@sobolevn
Copy link
Member

sobolevn commented Mar 6, 2025

I think that the error message can be improved, yes, thank you for noticing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants