Skip to content

gh-130928: Fix error message during bytes formatting for the 'i' flag #130967

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

Merged
merged 5 commits into from
Mar 24, 2025

Conversation

ApostolFet
Copy link
Contributor

@ApostolFet ApostolFet commented Mar 7, 2025

Error output before correction:

>>> 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

Error output after correction:

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

Copy link
Contributor

@jstasiak jstasiak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd add a unit test for this.

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please, add a unit test :)
And also a NEWS entry. This is a user-visible change.

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I think that the fix is correct.
But, let's wait for @serhiy-storchaka review, because his is the code owner.

@sobolevn
Copy link
Member

sobolevn commented Mar 9, 2025

You can also add yourself to https://github.com/python/cpython/blob/main/Misc/ACKS

@ApostolFet
Copy link
Contributor Author

You can also add yourself to https://github.com/python/cpython/blob/main/Misc/ACKS

Thanks, but I've already taken advantage of that opportunity earlier

@sobolevn
Copy link
Member

sobolevn commented Mar 9, 2025

I would also suggest to create a new issue to add tests for bytes formatting options. Please, tag me - I can assign you this issue if you want.

@sobolevn
Copy link
Member

@serhiy-storchaka friendly ping, what do you think? :)

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that test_common_format in test_format.py may be a better place for the tests. There are already tests for %d and %x. You can just add

        test_exc_common('%i', '1', TypeError,
                        "%i format: a real number is required, not str")

Or you can leave tests in both places.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again!

@sobolevn sobolevn merged commit 7c3692f into python:main Mar 24, 2025
46 checks passed
@sobolevn
Copy link
Member

We usually do not backport error message changes.

@ApostolFet ApostolFet deleted the fix-issue-130928 branch March 26, 2025 07:26
diegorusso pushed a commit to diegorusso/cpython that referenced this pull request Apr 1, 2025
seehwan pushed a commit to seehwan/cpython that referenced this pull request Apr 16, 2025
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

Successfully merging this pull request may close these issues.

4 participants