]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-109207: Fix SystemError when printing symtable entry object. (GH-109225...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 2 Oct 2023 14:55:41 +0000 (07:55 -0700)
committerGitHub <noreply@github.com>
Mon, 2 Oct 2023 14:55:41 +0000 (16:55 +0200)
gh-109207: Fix SystemError when printing symtable entry object. (GH-109225)
(cherry picked from commit 429749969621b149c1a7c3c004bd44f52bec8f44)

Co-authored-by: δΊ‘line <31395137+yunline@users.noreply.github.com>
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 61fda767e3ecd0fa9a91a8589ffc1def6f998fdc..82c1d7c856a1e599c46fec9fcffc4d0db3a5c959 100644 (file)
@@ -282,6 +282,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 865181273663c28329f433a2f22ebd5f8cd93b5d..70b6eacd4ac0715ea02473c5a40a3a82d9d91978 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