-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
bpo-36974: PEP 590 #13185
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
bpo-36974: PEP 590 #13185
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
099c58c
bpo-36974: minimal implementation of PEP 590
markshannon 01f3709
bpo-36974: implement PEP 590
jdemeyer f4b1224
bpo-36974: add PEP 590 tests
jdemeyer 424b44f
Convert macros to static inline functions
encukou c1f7a61
test_capi: Use unittest.subTest to make potential failures clearer
encukou 78a0644
Test both PyVectorcall_Call and _PyObject_Vectorcall; rename test fun…
encukou 7536e69
Return Py_EnterRecursiveCall to _PyObject_FastCallDict
encukou 83dec38
bpo-36974: revert "Return Py_EnterRecursiveCall to _PyObject_FastCall…
jdemeyer 9293187
bpo-36974: minor fixes to test_vectorcall()
jdemeyer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,11 @@ def testfunction(self): | |
"""some doc""" | ||
return self | ||
|
||
def testfunction_kw(self, *, kw): | ||
"""some doc""" | ||
return self | ||
|
||
|
||
class InstanceMethod: | ||
id = _testcapi.instancemethod(id) | ||
testfunction = _testcapi.instancemethod(testfunction) | ||
|
@@ -479,6 +484,47 @@ class MethodDescriptorHeap(_testcapi.MethodDescriptorBase): | |
pass | ||
self.assertFalse(MethodDescriptorHeap.__flags__ & Py_TPFLAGS_METHOD_DESCRIPTOR) | ||
|
||
def test_vectorcall(self): | ||
# Test a bunch of different ways to call objects: | ||
# 1. normal call | ||
# 2. vectorcall | ||
# 3. call as bound method | ||
# 4. call using functools.partial | ||
|
||
# A list of (function, args, kwargs, result) calls to test | ||
calls = [(len, (range(42),), {}, 42), | ||
(list.append, ([], 0), {}, None), | ||
([].append, (0,), {}, None), | ||
(sum, ([36],), {"start":6}, 42), | ||
(testfunction, (42,), {}, 42), | ||
(testfunction_kw, (42,), {"kw":None}, 42)] | ||
|
||
from _testcapi import pyobject_vectorcall, pyvectorcall_call | ||
from types import MethodType | ||
from functools import partial | ||
|
||
def vectorcall(func, args, kwargs=None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you want to set a default for |
||
args = *args, *kwargs.values() | ||
kwnames = tuple(kwargs) | ||
return pyobject_vectorcall(func, args, kwnames) | ||
|
||
for (func, args, kwargs, expected) in calls: | ||
with self.subTest(str(func)): | ||
args1 = args[1:] | ||
meth = MethodType(func, args[0]) | ||
wrapped = partial(func) | ||
if not kwargs: | ||
self.assertEqual(expected, func(*args)) | ||
self.assertEqual(expected, pyobject_vectorcall(func, args, None)) | ||
self.assertEqual(expected, pyvectorcall_call(func, args)) | ||
self.assertEqual(expected, meth(*args1)) | ||
self.assertEqual(expected, wrapped(*args)) | ||
self.assertEqual(expected, func(*args, **kwargs)) | ||
self.assertEqual(expected, vectorcall(func, args, kwargs)) | ||
self.assertEqual(expected, pyvectorcall_call(func, args, kwargs)) | ||
self.assertEqual(expected, meth(*args1, **kwargs)) | ||
self.assertEqual(expected, wrapped(*args, **kwargs)) | ||
|
||
|
||
class SubinterpreterTest(unittest.TestCase): | ||
|
||
|
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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 would be good to fix this comment, as you're adding a new way of testing the call.