-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
gh-94808: Cover %p
in PyUnicode_FromFormat
#96677
Conversation
And we got a failure: MacOS passes locally and on CI, but other platforms do not. Windows:
Ubuntu:
I think it is better to remove |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a regex test would be better here.
Good idea, thank you. |
Lib/test/test_unicode.py
Outdated
self.assertIsInstance(p_format1, str) | ||
self.assertRegex(p_format1, p_format_regex) | ||
|
||
p_format2 = PyUnicode_FromFormat(b'repr=%p', '123456', None, b'xyz') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this case test? I don't see what it adds over the previous case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has:
- Multiple arguments (while
p_format1
only has one arg) - All arguments have different types
- New types are tested:
bytes
andNone
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't the additional arguments ignored though, because there is only one %p
in the format string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, tests can be better :)
Can you please take a look at the updated version?
It now has both:
- Extra types
- Ignored arguments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
From https://github.com/python/cpython/actions/runs/3200613350/jobs/5227726848
This is quite interesting. Is |
Interesting! I think that comes from libc since I can't find code in CPython that would do this. |
From https://pubs.opengroup.org/onlinepubs/009695399/functions/fprintf.html
I think it is better to just leave Related discussions: |
I think ctypes translates None into NULL, which is reasonable. |
Thanks @sobolevn for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11. |
Sorry @sobolevn and @JelleZijlstra, I had trouble checking out the |
GH-98032 is a backport of this pull request to the 3.10 branch. |
Co-authored-by: Jelle Zijlstra <[email protected]> (cherry picked from commit 72c166a) Co-authored-by: Nikita Sobolev <[email protected]>
Thanks @sobolevn for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11. |
GH-98033 is a backport of this pull request to the 3.11 branch. |
Co-authored-by: Jelle Zijlstra <[email protected]> (cherry picked from commit 72c166a) Co-authored-by: Nikita Sobolev <[email protected]>
|
I guess the pointers are shorter on s390. I'll adjust the regex. |
|
|
) Co-authored-by: Nikita Sobolev <[email protected]> Co-authored-by: Jelle Zijlstra <[email protected]> (cherry picked from commit 72c166a)
) Co-authored-by: Nikita Sobolev <[email protected]> Co-authored-by: Jelle Zijlstra <[email protected]> (cherry picked from commit 72c166a)
Co-authored-by: Jelle Zijlstra <[email protected]>
Source:
cpython/Objects/unicodeobject.c
Lines 2531 to 2552 in 4f523a7
Internet says that some systems can return representation with
0x
, some with0X
, and some with none. It is reflected in the implementation, but cannot be reflected in tests.