mirror of
https://github.com/python/cpython.git
synced 2025-08-28 04:35:02 +00:00
[3.11] gh-109207: Fix SystemError when printing symtable entry object. (GH-109225) (GH-109228)
(cherry picked from commit 4297499696
)
Co-authored-by: 云line <31395137+yunline@users.noreply.github.com>
This commit is contained in:
parent
77356f6f96
commit
c20658249d
3 changed files with 7 additions and 3 deletions
|
@ -252,6 +252,10 @@ class SymtableTest(unittest.TestCase):
|
||||||
self.assertEqual(str(self.top), "<SymbolTable for module ?>")
|
self.assertEqual(str(self.top), "<SymbolTable for module ?>")
|
||||||
self.assertEqual(str(self.spam), "<Function SymbolTable for spam in ?>")
|
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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Fix a SystemError in ``__repr__`` of symtable entry object.
|
|
@ -128,9 +128,8 @@ ste_new(struct symtable *st, identifier name, _Py_block_ty block,
|
||||||
static PyObject *
|
static PyObject *
|
||||||
ste_repr(PySTEntryObject *ste)
|
ste_repr(PySTEntryObject *ste)
|
||||||
{
|
{
|
||||||
return PyUnicode_FromFormat("<symtable entry %U(%ld), line %d>",
|
return PyUnicode_FromFormat("<symtable entry %U(%R), line %d>",
|
||||||
ste->ste_name,
|
ste->ste_name, ste->ste_id, ste->ste_lineno);
|
||||||
PyLong_AS_LONG(ste->ste_id), ste->ste_lineno);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue