FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-135855: Fix `SystemError` when passing non-dict object to `_interpreters.set___main___attrs` by brianschubert · Pull Request #135856 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension .c  (2) .py  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
Prev Previous commit
Remove redundant Py_None check, add None tests, add assert
  • Loading branch information
brianschubert committed Jun 24, 2025
commit f400fb8d33950623c874156d672d054703aa71e5
11 changes: 11 additions & 0 deletions Lib/test/test__interpreters.py
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
Expand Up @@ -490,6 +490,17 @@ def test_signatures(self):
with self.assertRaisesRegex(TypeError, msg):
_interpreters.set___main___attrs(self.id, 1)

def test_invalid_shared_none(self):
msg = r'must be dict, not None'
with self.assertRaisesRegex(TypeError, msg):
_interpreters.exec(self.id, 'a', shared=None)
with self.assertRaisesRegex(TypeError, msg):
_interpreters.run_string(self.id, 'a', shared=None)
with self.assertRaisesRegex(TypeError, msg):
_interpreters.run_func(self.id, lambda: None, shared=None)
with self.assertRaisesRegex(TypeError, msg):
_interpreters.set___main___attrs(self.id, None)

def test_invalid_shared_encoding(self):
# See https://github.com/python/cpython/issues/127196
bad_shared = {"\uD82A": 0}
Expand Down
18 changes: 8 additions & 10 deletions Modules/_interpretersmodule.c
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
Expand Up @@ -1054,16 +1054,14 @@ interp_set___main___attrs(PyObject *self, PyObject *args, PyObject *kwargs)
}

// Check the updates.
if (updates != Py_None) {
Py_ssize_t size = PyDict_Size(updates);
if (size < 0) {
return NULL;
}
if (size == 0) {
PyErr_SetString(PyExc_ValueError,
"arg 2 must be a non-empty dict");
return NULL;
}
Py_ssize_t size = PyDict_Size(updates);
if (size < 0) {
return NULL;
}
if (size == 0) {
PyErr_SetString(PyExc_ValueError,
"arg 2 must be a non-empty dict");
return NULL;
}

_PyXI_session *session = _PyXI_NewSession();
Expand Down
1 change: 1 addition & 0 deletions Python/crossinterp.c
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
Expand Up @@ -2617,6 +2617,7 @@ _PyXI_Enter(_PyXI_session *session,
// Convert the attrs for cross-interpreter use.
_PyXI_namespace *sharedns = NULL;
if (nsupdates != NULL) {
assert(PyDict_Check(nsupdates));
Py_ssize_t len = PyDict_Size(nsupdates);
if (len < 0) {
if (result != NULL) {
Expand Down

Back | FazBrowse Home | New Git URL