Skip to content

Commit c206582

Browse files
[3.11] gh-109207: Fix SystemError when printing symtable entry object. (GH-109225) (GH-109228)
(cherry picked from commit 4297499) Co-authored-by: 云line <[email protected]>
1 parent 77356f6 commit c206582

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

Lib/test/test_symtable.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ def test_symtable_repr(self):
252252
self.assertEqual(str(self.top), "<SymbolTable for module ?>")
253253
self.assertEqual(str(self.spam), "<Function SymbolTable for spam in ?>")
254254

255+
def test_symtable_entry_repr(self):
256+
expected = f"<symtable entry top({self.top.get_id()}), line {self.top.get_lineno()}>"
257+
self.assertEqual(repr(self.top._table), expected)
258+
255259

256260
if __name__ == '__main__':
257261
unittest.main()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a SystemError in ``__repr__`` of symtable entry object.

Python/symtable.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,8 @@ ste_new(struct symtable *st, identifier name, _Py_block_ty block,
128128
static PyObject *
129129
ste_repr(PySTEntryObject *ste)
130130
{
131-
return PyUnicode_FromFormat("<symtable entry %U(%ld), line %d>",
132-
ste->ste_name,
133-
PyLong_AS_LONG(ste->ste_id), ste->ste_lineno);
131+
return PyUnicode_FromFormat("<symtable entry %U(%R), line %d>",
132+
ste->ste_name, ste->ste_id, ste->ste_lineno);
134133
}
135134

136135
static void

0 commit comments

Comments
 (0)