[3.13] gh-132171: Fix _interpreters.run_string crash on string subclass (GH-132173) (#132219)

gh-132171: Fix `_interpreters.run_string` crash on string subclass (GH-132173)
(cherry picked from commit 3980718710)

Co-authored-by: sobolevn <mail@sobolevn.me>
This commit is contained in:
Miss Islington (bot) 2025-04-07 14:23:02 +02:00 committed by GitHub
parent 71b537572a
commit 6afab81f72
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 1 deletions

View file

@ -745,6 +745,12 @@ class RunStringTests(TestBase):
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()