Skip to content

Commit be8255a

Browse files
[3.12] gh-109207: Fix SystemError when printing symtable entry object. (GH-109225) (#109227)
gh-109207: Fix SystemError when printing symtable entry object. (GH-109225) (cherry picked from commit 4297499) Co-authored-by: 云line <[email protected]>
1 parent 1c223ae commit be8255a

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
@@ -282,6 +282,10 @@ def test_symtable_repr(self):
282282
self.assertEqual(str(self.top), "<SymbolTable for module ?>")
283283
self.assertEqual(str(self.spam), "<Function SymbolTable for spam in ?>")
284284

285+
def test_symtable_entry_repr(self):
286+
expected = f"<symtable entry top({self.top.get_id()}), line {self.top.get_lineno()}>"
287+
self.assertEqual(repr(self.top._table), expected)
288+
285289

286290
if __name__ == '__main__':
287291
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
@@ -150,9 +150,8 @@ ste_new(struct symtable *st, identifier name, _Py_block_ty block,
150150
static PyObject *
151151
ste_repr(PySTEntryObject *ste)
152152
{
153-
return PyUnicode_FromFormat("<symtable entry %U(%ld), line %d>",
154-
ste->ste_name,
155-
PyLong_AS_LONG(ste->ste_id), ste->ste_lineno);
153+
return PyUnicode_FromFormat("<symtable entry %U(%R), line %d>",
154+
ste->ste_name, ste->ste_id, ste->ste_lineno);
156155
}
157156

158157
static void

0 commit comments

Comments
 (0)