Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1a6b7bb

Browse files
committed
Deprecate co_lnotab instead of removing it
1 parent dd65849 commit 1a6b7bb

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

Doc/whatsnew/3.12.rst

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

519+
* Accessing ``co_lnotab`` was deprecated in :pep:`626` since 3.10
520+
and was planned to be removed in 3.12
521+
but it only got a proper :exc:`DeprecationWarning` in 3.12.
522+
Remove it in 3.14.
523+
(Contributed by Nikita Sobolev in :gh:`101866`.)
524+
519525
Pending Removal in Future Versions
520526
----------------------------------
521527

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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,6 +1884,13 @@ static PyMemberDef code_memberlist[] = {
18841884
static PyObject *
18851885
code_getlnotab(PyCodeObject *code, void *closure)
18861886
{
1887+
if (PyErr_WarnEx(PyExc_DeprecationWarning,
1888+
"co_lnotab is deprecated since Python 3.12 "
1889+
"and will be removed in Python 3.14, "
1890+
"use co_lines instead.",
1891+
1) < 0) {
1892+
return NULL;
1893+
}
18871894
return decode_linetable(code);
18881895
}
18891896

0 commit comments

Comments
 (0)