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

@ApostolFet

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

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