]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] gh-109207: Fix SystemError when printing symtable entry object. (GH-109225...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 10 Sep 2023 13:50:22 +0000 (06:50 -0700)
committerGitHub <noreply@github.com>
Sun, 10 Sep 2023 13:50:22 +0000 (16:50 +0300)
(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 819354e4eee9b5e03852d34daf1b17691f9b6f1b..f38d791c83d41d3f2db4afbf9bbf487e9e52278a 100644 (file)
@@ -252,6 +252,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 afe05c71b97d9da968b8435e58c5c8ae89b4f249..37e5c697405b1a21f3c33c4c52e45cdead82d04c 100644 (file)
@@ -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