]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-101865: Deprecate `co_lnotab` from code objects as per PEP 626 (#101866)
authorNikita Sobolev <mail@sobolevn.me>
Mon, 3 Apr 2023 15:35:04 +0000 (18:35 +0300)
committerGitHub <noreply@github.com>
Mon, 3 Apr 2023 15:35:04 +0000 (17:35 +0200)
Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
Doc/reference/datamodel.rst
Doc/whatsnew/3.12.rst
Lib/test/test_code.py
Misc/NEWS.d/next/Core and Builtins/2023-02-21-17-22-06.gh-issue-101865.fwrTOA.rst [new file with mode: 0644]
Objects/codeobject.c

index 1865d09fcaa1279b513ab1c5d60d320c3a39bd7b..a09d5529c8c6f9067b986fc24a80442749fa0dbb 100644 (file)
@@ -991,7 +991,8 @@ Internal types
       the filename from which the code was compiled; :attr:`co_firstlineno` is
       the first line number of the function; :attr:`co_lnotab` is a string
       encoding the mapping from bytecode offsets to line numbers (for details
-      see the source code of the interpreter); :attr:`co_stacksize` is the
+      see the source code of the interpreter, is deprecated since 3.12
+      and may be removed in 3.14); :attr:`co_stacksize` is the
       required stack size; :attr:`co_flags` is an integer encoding a number
       of flags for the interpreter.
 
index 3df3ef711a90e588bbc9ca25ac830fe4dbb2cfa2..88b99828f0beeb829a9fea5f6a7966cb711cb252 100644 (file)
@@ -622,6 +622,12 @@ Pending Removal in Python 3.14
   functions that have been deprecated since Python 2 but only gained a
   proper :exc:`DeprecationWarning` in 3.12. Remove them in 3.14.
 
+* Accessing ``co_lnotab`` was deprecated in :pep:`626` since 3.10
+  and was planned to be removed in 3.12
+  but it only got a proper :exc:`DeprecationWarning` in 3.12.
+  May be removed in 3.14.
+  (Contributed by Nikita Sobolev in :gh:`101866`.)
+
 * The *onerror* argument of :func:`shutil.rmtree` is deprecated in 3.12,
   and will be removed in 3.14.
 
index 0cd1fb3f9728e58ab313190a6a2d2d91e76c348f..7543c9ab34211922b1974d8b475a44caf43ea03a 100644 (file)
@@ -338,6 +338,13 @@ class CodeTest(unittest.TestCase):
         new_code = code = func.__code__.replace(co_linetable=b'')
         self.assertEqual(list(new_code.co_lines()), [])
 
+    def test_co_lnotab_is_deprecated(self):  # TODO: remove in 3.14
+        def func():
+            pass
+
+        with self.assertWarns(DeprecationWarning):
+            func.__code__.co_lnotab
+
     def test_invalid_bytecode(self):
         def foo():
             pass
diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-02-21-17-22-06.gh-issue-101865.fwrTOA.rst b/Misc/NEWS.d/next/Core and Builtins/2023-02-21-17-22-06.gh-issue-101865.fwrTOA.rst
new file mode 100644 (file)
index 0000000..876cc22
--- /dev/null
@@ -0,0 +1,2 @@
+Deprecate ``co_lnotab`` in code objects, schedule it for removal in Python
+3.14
index 65b1d258fb76afd2c691eea1c5b4e16589a3ccae..755d0b85e7cf300a0eec250a834499235e1079e8 100644 (file)
@@ -1921,6 +1921,11 @@ static PyMemberDef code_memberlist[] = {
 static PyObject *
 code_getlnotab(PyCodeObject *code, void *closure)
 {
+    if (PyErr_WarnEx(PyExc_DeprecationWarning,
+                     "co_lnotab is deprecated, use co_lines instead.",
+                     1) < 0) {
+        return NULL;
+    }
     return decode_linetable(code);
 }