]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-109207: Fix SystemError when printing symtable entry object. (GH-109225)
author云line <31395137+yunline@users.noreply.github.com>
Sun, 10 Sep 2023 12:04:24 +0000 (20:04 +0800)
committerGitHub <noreply@github.com>
Sun, 10 Sep 2023 12:04:24 +0000 (15:04 +0300)
Lib/test/test_symtable.py
Misc/NEWS.d/next/Core and Builtins/2023-09-10-18-53-55.gh-issue-109207.Fei8bY.rst [new file with mode: 0644]
Python/symtable.c

index 25714aecda3a1525571b7e4b68ab523154c24d7d..36cb7b3f242e4cc659cb4e476baffbe2fe2c04a2 100644 (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()
diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-09-10-18-53-55.gh-issue-109207.Fei8bY.rst b/Misc/NEWS.d/next/Core and Builtins/2023-09-10-18-53-55.gh-issue-109207.Fei8bY.rst
new file mode 100644 (file)
index 0000000..f9da3ac
--- /dev/null
@@ -0,0 +1 @@
+Fix a SystemError in ``__repr__`` of symtable entry object.
index 7eef6f7231c035d436ca445a4515baf0a511899d..6c28b49a0655c635d5e27207d6fc5bbc359bfc12 100644 (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