-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-101072: support default and kw default in PyEval_EvalCodeEx for 3.11+ #101127
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
ambv
merged 6 commits into
python:main
from
MatthieuDartiailh:pyeval_evalcodeex_default_support
Feb 7, 2023
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f95777b
do not ignore default argument values in _PyFunction_FromConstructor
MatthieuDartiailh 0bb1c96
test: add a test for PyEval_EvalCodeEx
MatthieuDartiailh ce402c3
test: attempt to abide by PEP 7
MatthieuDartiailh 792d5c7
Merge branch 'main' into pyeval_evalcodeex_default_support
ambv a5ece93
Add Blurb
ambv f14a0e5
Fix refleak and formatting
ambv 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import unittest | ||
|
||
from test.support import import_helper | ||
|
||
|
||
# Skip this test if the _testcapi module isn't available. | ||
_testcapi = import_helper.import_module('_testcapi') | ||
|
||
|
||
class PyEval_EvalCodeExTests(unittest.TestCase): | ||
|
||
def test_simple(self): | ||
def f(): | ||
return a | ||
|
||
self.assertEqual(_testcapi.eval_code_ex(f.__code__, dict(a=1)), 1) | ||
|
||
# Need to force the compiler to use LOAD_NAME | ||
# def test_custom_locals(self): | ||
# def f(): | ||
# return | ||
|
||
def test_with_args(self): | ||
def f(a, b, c): | ||
return a | ||
|
||
self.assertEqual(_testcapi.eval_code_ex(f.__code__, {}, {}, (1, 2, 3)), 1) | ||
|
||
def test_with_kwargs(self): | ||
def f(a, b, c): | ||
return a | ||
|
||
self.assertEqual(_testcapi.eval_code_ex(f.__code__, {}, {}, (), dict(a=1, b=2, c=3)), 1) | ||
|
||
def test_with_default(self): | ||
def f(a): | ||
return a | ||
|
||
self.assertEqual(_testcapi.eval_code_ex(f.__code__, {}, {}, (), {}, (1,)), 1) | ||
|
||
def test_with_kwarg_default(self): | ||
def f(*, a): | ||
return a | ||
|
||
self.assertEqual(_testcapi.eval_code_ex(f.__code__, {}, {}, (), {}, (), dict(a=1)), 1) | ||
|
||
def test_with_closure(self): | ||
a = 1 | ||
def f(): | ||
return a | ||
|
||
self.assertEqual(_testcapi.eval_code_ex(f.__code__, {}, {}, (), {}, (), {}, f.__closure__), 1) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
8 changes: 8 additions & 0 deletions
8
Misc/NEWS.d/next/Core and Builtins/2023-02-06-20-13-36.gh-issue-92173.RQE0mk.rst
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
macOS #.. section: IDLE #.. section: Tools/Demos #.. section: C API | ||
|
||
# Write your Misc/NEWS entry below. It should be a simple ReST paragraph. # | ||
Don't start with "- Issue #<n>: " or "- gh-issue-<n>: " or that sort of | ||
stuff. | ||
########################################################################### | ||
|
||
Fix the ``defs`` and ``kwdefs`` arguments to :c:func:`PyEval_EvalCodeEx`. |
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 |
---|---|---|
|
@@ -1761,9 +1761,6 @@ PyEval_EvalCodeEx(PyObject *_co, PyObject *globals, PyObject *locals, | |
} | ||
allargs = newargs; | ||
} | ||
for (int i = 0; i < kwcount; i++) { | ||
PyTuple_SET_ITEM(kwnames, i, Py_NewRef(kws[2*i])); | ||
} | ||
Comment on lines
-1764
to
-1766
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. This code is duplicated in the block right above, leading to double new refs. |
||
PyFrameConstructor constr = { | ||
.fc_globals = globals, | ||
.fc_builtins = builtins, | ||
|
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.
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.
@ambv Looks like there are compiler warnings. See L-3152
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.
Good catch, looks like
PyEval_EvalCodeEx
lists those arguments simply asint
s. I'll convert this code to do the same.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.
Nikita reported this as GH-101656.