Thanks to visit codestin.com
Credit goes to github.com

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
gh-109207: Fix SystemError when printing symtable entry object. (GH-1…
…09225)

(cherry picked from commit 4297499)

Co-authored-by: 云line <[email protected]>
  • Loading branch information
yunline authored and miss-islington committed Sep 10, 2023
commit 220c95115af86689fb80fdd24d587f3076a2a245
4 changes: 4 additions & 0 deletions Lib/test/test_symtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ def test_symtable_repr(self):
self.assertEqual(str(self.top), "<SymbolTable for module ?>")
self.assertEqual(str(self.spam), "<Function SymbolTable for spam in ?>")

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


if __name__ == '__main__':
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a SystemError in ``__repr__`` of symtable entry object.
5 changes: 2 additions & 3 deletions Python/symtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,8 @@ ste_new(struct symtable *st, identifier name, _Py_block_ty block,
static PyObject *
ste_repr(PySTEntryObject *ste)
{
return PyUnicode_FromFormat("<symtable entry %U(%ld), line %d>",
ste->ste_name,
PyLong_AS_LONG(ste->ste_id), ste->ste_lineno);
return PyUnicode_FromFormat("<symtable entry %U(%R), line %d>",
ste->ste_name, ste->ste_id, ste->ste_lineno);
}

static void
Expand Down