Skip to content

Commit 2db2a84

Browse files
sobolevnarhadthedev
authored andcommitted
pythongh-101865: Deprecate co_lnotab from code objects as per PEP 626 (python#101866)
Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
1 parent 19d5b50 commit 2db2a84

File tree

5 files changed

+22
-1
lines changed

5 files changed

+22
-1
lines changed

Doc/reference/datamodel.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,8 @@ Internal types
991991
the filename from which the code was compiled; :attr:`co_firstlineno` is
992992
the first line number of the function; :attr:`co_lnotab` is a string
993993
encoding the mapping from bytecode offsets to line numbers (for details
994-
see the source code of the interpreter); :attr:`co_stacksize` is the
994+
see the source code of the interpreter, is deprecated since 3.12
995+
and may be removed in 3.14); :attr:`co_stacksize` is the
995996
required stack size; :attr:`co_flags` is an integer encoding a number
996997
of flags for the interpreter.
997998

Doc/whatsnew/3.12.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,12 @@ Pending Removal in Python 3.14
622622
functions that have been deprecated since Python 2 but only gained a
623623
proper :exc:`DeprecationWarning` in 3.12. Remove them in 3.14.
624624

625+
* Accessing ``co_lnotab`` was deprecated in :pep:`626` since 3.10
626+
and was planned to be removed in 3.12
627+
but it only got a proper :exc:`DeprecationWarning` in 3.12.
628+
May be removed in 3.14.
629+
(Contributed by Nikita Sobolev in :gh:`101866`.)
630+
625631
* The *onerror* argument of :func:`shutil.rmtree` is deprecated in 3.12,
626632
and will be removed in 3.14.
627633

Lib/test/test_code.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,13 @@ def func():
338338
new_code = code = func.__code__.replace(co_linetable=b'')
339339
self.assertEqual(list(new_code.co_lines()), [])
340340

341+
def test_co_lnotab_is_deprecated(self): # TODO: remove in 3.14
342+
def func():
343+
pass
344+
345+
with self.assertWarns(DeprecationWarning):
346+
func.__code__.co_lnotab
347+
341348
def test_invalid_bytecode(self):
342349
def foo():
343350
pass
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Deprecate ``co_lnotab`` in code objects, schedule it for removal in Python
2+
3.14

Objects/codeobject.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,6 +1921,11 @@ static PyMemberDef code_memberlist[] = {
19211921
static PyObject *
19221922
code_getlnotab(PyCodeObject *code, void *closure)
19231923
{
1924+
if (PyErr_WarnEx(PyExc_DeprecationWarning,
1925+
"co_lnotab is deprecated, use co_lines instead.",
1926+
1) < 0) {
1927+
return NULL;
1928+
}
19241929
return decode_linetable(code);
19251930
}
19261931

0 commit comments

Comments
 (0)