Skip to content

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

Closed

Description

@ApostolFet

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

Activity

  1. sobolevn commented on Mar 6, 2025

    @sobolevn
    Member

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

  2. added a commit that references this issue on Mar 24, 2025
  3. added a commit that references this issue on Apr 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions