gh-117709: Add vectorcall support for positional-only arguments of str()#117746
Merged
erlend-aasland merged 19 commits intopython:mainfrom Apr 11, 2024
Merged
Conversation
erlend-aasland
commented
Apr 11, 2024
Misc/NEWS.d/next/Core and Builtins/2024-04-10-22-16-18.gh-issue-117709.-_1YL0.rst
Outdated
Show resolved
Hide resolved
erlend-aasland
commented
Apr 11, 2024
Contributor
Author
|
The speedups are as with #117725, but only for the positional-only cases. Summary of the benchmarks1:
Footnotes
|
vstinner
reviewed
Apr 11, 2024
| } | ||
| return str; | ||
| } | ||
|
|
Member
There was a problem hiding this comment.
You may add a comment to mention that this function is a fast-path for positional-only cases.
corona10
reviewed
Apr 11, 2024
Member
corona10
left a comment
There was a problem hiding this comment.
I personally prefer this one :)
Do we have enough tests for positional arguments cases?
Contributor
Author
Well, we could add something like this: Detailsdiff --git a/Lib/test/test_str.py b/Lib/test/test_str.py
index b4927113db..ea37eb5d96 100644
--- a/Lib/test/test_str.py
+++ b/Lib/test/test_str.py
@@ -2651,6 +2651,24 @@ def test_check_encoding_errors(self):
proc = assert_python_failure('-X', 'dev', '-c', code)
self.assertEqual(proc.rc, 10, proc)
+ def test_str_invalid_call(self):
+ check = lambda *a, **kw: self.assertRaises(TypeError, str, *a, **kw)
+
+ # too many args
+ check(1, "", "", 1)
+
+ # no such kw arg
+ check(test=1)
+
+ # 'encoding' must be str
+ check(1, encoding=1)
+ check(1, 1)
+
+ # 'errors' must be str
+ check(1, errors=1)
+ check(1, "", errors=1)
+ check(1, 1, 1)
+
class StringModuleTest(unittest.TestCase):
def test_formatter_parser(self):UPDATE: added in 8138db4 |
corona10
reviewed
Apr 11, 2024
erlend-aasland
commented
Apr 11, 2024
erlend-aasland
commented
Apr 11, 2024
vstinner
approved these changes
Apr 11, 2024
Co-authored-by: Victor Stinner <vstinner@python.org>
Contributor
Author
|
Thank you so much for the reviews, Donghee and Victor! |
diegorusso
pushed a commit
to diegorusso/cpython
that referenced
this pull request
Apr 17, 2024
…y arguments (python#117746) Fall back to tp_call() for cases when arguments are passed by name. Co-authored-by: Donghee Na <donghee.na@python.org> Co-authored-by: Victor Stinner <vstinner@python.org>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Competing PR to gh-117725.
PyUnicode_Typeneeds vectorcall. #117709