Skip to content

Commit

Permalink
Deprecate co_lnotab instead of removing it
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn committed Feb 21, 2023
1 parent dd65849 commit 1a6b7bb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Doc/whatsnew/3.12.rst
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,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.
Remove it in 3.14.
(Contributed by Nikita Sobolev in :gh:`101866`.)

Pending Removal in Future Versions
----------------------------------

Expand Down
7 changes: 7 additions & 0 deletions Lib/test/test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,13 @@ def func():
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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Deprecate ``co_lnotab`` in code objects, schedule it for removal in Python
3.14
7 changes: 7 additions & 0 deletions Objects/codeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1884,6 +1884,13 @@ static PyMemberDef code_memberlist[] = {
static PyObject *
code_getlnotab(PyCodeObject *code, void *closure)
{
if (PyErr_WarnEx(PyExc_DeprecationWarning,
"co_lnotab is deprecated since Python 3.12 "
"and will be removed in Python 3.14, "
"use co_lines instead.",
1) < 0) {
return NULL;
}
return decode_linetable(code);
}

Expand Down

0 comments on commit 1a6b7bb

Please sign in to comment.