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.
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.
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
--- /dev/null
+Deprecate ``co_lnotab`` in code objects, schedule it for removal in Python
+3.14
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);
}