Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2a72125

Browse files
gh-101865: Deprecateco_lnotab from code objects as per PEP 626 (#101866)
Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
1 parente6f7d35 commit2a72125

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+
deftest_co_lnotab_is_deprecated(self):# TODO: remove in 3.14
342+
deffunc():
343+
pass
344+
345+
withself.assertWarns(DeprecationWarning):
346+
func.__code__.co_lnotab
347+
341348
deftest_invalid_bytecode(self):
342349
deffoo():
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
staticPyObject*
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+
returnNULL;
1928+
}
19241929
returndecode_linetable(code);
19251930
}
19261931

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp