gh-109207: Fix SystemError when printing symtable entry object. (GH-109225)

This commit is contained in:
云line 2023-09-10 20:04:24 +08:00 committed by GitHub
parent 2dd6a86c4e
commit 4297499696
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 3 deletions

View File

@ -251,6 +251,10 @@ class SymtableTest(unittest.TestCase):
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()

View File

@ -0,0 +1 @@
Fix a SystemError in ``__repr__`` of symtable entry object.

View File

@ -150,9 +150,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