Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Lib/test/test__interpreters.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,12 @@ def test_bytes_for_script(self):
with self.assertRaises(TypeError):
_interpreters.run_string(self.id, b'print("spam")')

def test_str_subclass_string(self):
class StrSubclass(str): pass

output = _run_output(self.id, StrSubclass('print(1 + 2)'))
self.assertEqual(output, '3\n')

def test_with_shared(self):
r, w = os.pipe()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix crash of ``_interpreters.run_string`` on string subclasses.
2 changes: 1 addition & 1 deletion Modules/_interpretersmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ get_code_str(PyObject *arg, Py_ssize_t *len_p, PyObject **bytes_p, int *flags_p)
int flags = 0;

if (PyUnicode_Check(arg)) {
assert(PyUnicode_CheckExact(arg)
assert(PyUnicode_Check(arg)
&& (check_code_str((PyUnicodeObject *)arg) == NULL));
codestr = PyUnicode_AsUTF8AndSize(arg, &len);
if (codestr == NULL) {
Expand Down
Loading