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

Commit06a79d9

Browse files
committed
gh-101865: Remove deprecatedco_lnotab from code objects as per PEP626
1 parent6ef6915 commit06a79d9

File tree

9 files changed

+12
-340
lines changed

9 files changed

+12
-340
lines changed

‎Doc/library/inspect.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,6 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
164164
||| read more:ref:`here|
165165
||| <inspect-module-co-flags>`|
166166
+-----------+-------------------+---------------------------+
167-
|| co_lnotab| encoded mapping of line|
168-
||| numbers to bytecode|
169-
||| indices|
170-
+-----------+-------------------+---------------------------+
171167
|| co_freevars| tuple of names of free|
172168
||| variables (referenced via|
173169
||| a function's closure)|

‎Doc/reference/datamodel.rst

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,6 @@ Internal types
962962
single: co_filename (code object attribute)
963963
single: co_firstlineno (code object attribute)
964964
single: co_flags (code object attribute)
965-
single: co_lnotab (code object attribute)
966965
single: co_name (code object attribute)
967966
single: co_names (code object attribute)
968967
single: co_nlocals (code object attribute)
@@ -989,9 +988,7 @@ Internal types
989988
a tuple containing the literals used by the bytecode;:attr:`co_names` is
990989
a tuple containing the names used by the bytecode;:attr:`co_filename` is
991990
the filename from which the code was compiled;:attr:`co_firstlineno` is
992-
the first line number of the function;:attr:`co_lnotab` is a string
993-
encoding the mapping from bytecode offsets to line numbers (for details
994-
see the source code of the interpreter);:attr:`co_stacksize` is the
991+
the first line number of the function;:attr:`co_stacksize` is the
995992
required stack size;:attr:`co_flags` is an integer encoding a number
996993
of flags for the interpreter.
997994

‎Doc/whatsnew/3.12.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,10 @@ Removed
700700
*context* parameter instead.
701701
(Contributed by Victor Stinner in:gh:`94172`.)
702702

703+
* Remove ``co_lnotab`` attribute from code objects per:pep:`626`:
704+
use ``co_lines`` method instead.
705+
(Contributed by Nikita Sobolev in:gh:`101865`.)
706+
703707

704708
Porting to Python 3.12
705709
======================

‎Lib/inspect.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,6 @@ def iscode(object):
499499
co_freevars tuple of names of free variables
500500
co_posonlyargcount number of positional only arguments
501501
co_kwonlyargcount number of keyword only arguments (not including ** arg)
502-
co_lnotab encoded mapping of line numbers to bytecode indices
503502
co_name name with which this code object was defined
504503
co_names tuple of names other than arguments and function locals
505504
co_nlocals number of local variables
@@ -1708,7 +1707,6 @@ def getframeinfo(frame, context=1):
17081707

17091708
defgetlineno(frame):
17101709
"""Get the line number from a frame object, allowing for optimization."""
1711-
# FrameType.f_lineno is now a descriptor that grovels co_lnotab
17121710
returnframe.f_lineno
17131711

17141712
_FrameInfo=namedtuple('_FrameInfo', ('frame',)+Traceback._fields)

‎Lib/pydoc_data/topics.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# Autogenerated by Sphinx onTue Feb 7 13:18:04 2023
2+
# Autogenerated by Sphinx onMon Feb13 10:21:05 2023
33
topics = {'assert': 'The "assert" statement\n'
44
'**********************\n'
55
'\n'
@@ -13704,13 +13704,10 @@
1370413704
' bytecode; "co_filename" is the filename from which the code '
1370513705
'was\n'
1370613706
' compiled; "co_firstlineno" is the first line number of the\n'
13707-
' function; "co_lnotab" is a string encoding the mapping from\n'
13708-
' bytecode offsets to line numbers (for details see the source\n'
13709-
' code of the interpreter); "co_stacksize" is the required '
13710-
'stack\n'
13711-
' size; "co_flags" is an integer encoding a number of flags '
13712-
'for\n'
13713-
' the interpreter.\n'
13707+
' function; "co_stacksize" is the required stack size; '
13708+
'"co_flags"\n'
13709+
' is an integer encoding a number of flags for the '
13710+
'interpreter.\n'
1371413711
'\n'
1371513712
' The following flag bits are defined for "co_flags": bit '
1371613713
'"0x04"\n'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove deprecated ``co_lnotab`` from code objects as per:pep:`626`.

‎Misc/gdbinit

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,7 @@ end
5454
# A rewrite of the Python interpreter's line number calculator in GDB's
5555
# command language
5656
define lineno
57-
set $__continue = 1
58-
set $__co = f->f_code
59-
set $__lasti = f->f_lasti
60-
set $__sz = ((PyVarObject *)$__co->co_lnotab)->ob_size/2
61-
set $__p = (unsigned char *)((PyBytesObject *)$__co->co_lnotab)->ob_sval
62-
set $__li = $__co->co_firstlineno
63-
set $__ad = 0
64-
while ($__sz-1 >= 0 && $__continue)
65-
set $__sz = $__sz - 1
66-
set $__ad = $__ad + *$__p
67-
set $__p = $__p + 1
68-
if ($__ad > $__lasti)
69-
set $__continue = 0
70-
else
71-
set $__li = $__li + *$__p
72-
set $__p = $__p + 1
73-
end
74-
end
75-
printf "%d", $__li
57+
printf "%d", f->f_lineno
7658
end
7759

7860
define pyframev

‎Objects/codeobject.c

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,77 +1097,6 @@ _PyLineTable_NextAddressRange(PyCodeAddressRange *range)
10971097
return1;
10981098
}
10991099

1100-
staticint
1101-
emit_pair(PyObject**bytes,int*offset,inta,intb)
1102-
{
1103-
Py_ssize_tlen=PyBytes_GET_SIZE(*bytes);
1104-
if (*offset+2 >=len) {
1105-
if (_PyBytes_Resize(bytes,len*2)<0)
1106-
return0;
1107-
}
1108-
unsignedchar*lnotab= (unsignedchar*)PyBytes_AS_STRING(*bytes);
1109-
lnotab+=*offset;
1110-
*lnotab++=a;
1111-
*lnotab++=b;
1112-
*offset+=2;
1113-
return1;
1114-
}
1115-
1116-
staticint
1117-
emit_delta(PyObject**bytes,intbdelta,intldelta,int*offset)
1118-
{
1119-
while (bdelta>255) {
1120-
if (!emit_pair(bytes,offset,255,0)) {
1121-
return0;
1122-
}
1123-
bdelta-=255;
1124-
}
1125-
while (ldelta>127) {
1126-
if (!emit_pair(bytes,offset,bdelta,127)) {
1127-
return0;
1128-
}
1129-
bdelta=0;
1130-
ldelta-=127;
1131-
}
1132-
while (ldelta<-128) {
1133-
if (!emit_pair(bytes,offset,bdelta,-128)) {
1134-
return0;
1135-
}
1136-
bdelta=0;
1137-
ldelta+=128;
1138-
}
1139-
returnemit_pair(bytes,offset,bdelta,ldelta);
1140-
}
1141-
1142-
staticPyObject*
1143-
decode_linetable(PyCodeObject*code)
1144-
{
1145-
PyCodeAddressRangebounds;
1146-
PyObject*bytes;
1147-
inttable_offset=0;
1148-
intcode_offset=0;
1149-
intline=code->co_firstlineno;
1150-
bytes=PyBytes_FromStringAndSize(NULL,64);
1151-
if (bytes==NULL) {
1152-
returnNULL;
1153-
}
1154-
_PyCode_InitAddressRange(code,&bounds);
1155-
while (_PyLineTable_NextAddressRange(&bounds)) {
1156-
if (bounds.opaque.computed_line!=line) {
1157-
intbdelta=bounds.ar_start-code_offset;
1158-
intldelta=bounds.opaque.computed_line-line;
1159-
if (!emit_delta(&bytes,bdelta,ldelta,&table_offset)) {
1160-
Py_DECREF(bytes);
1161-
returnNULL;
1162-
}
1163-
code_offset=bounds.ar_start;
1164-
line=bounds.opaque.computed_line;
1165-
}
1166-
}
1167-
_PyBytes_Resize(&bytes,table_offset);
1168-
returnbytes;
1169-
}
1170-
11711100

11721101
typedefstruct {
11731102
PyObject_HEAD
@@ -1881,12 +1810,6 @@ static PyMemberDef code_memberlist[] = {
18811810
};
18821811

18831812

1884-
staticPyObject*
1885-
code_getlnotab(PyCodeObject*code,void*closure)
1886-
{
1887-
returndecode_linetable(code);
1888-
}
1889-
18901813
staticPyObject*
18911814
code_getvarnames(PyCodeObject*code,void*closure)
18921815
{
@@ -1919,7 +1842,6 @@ code_getcode(PyCodeObject *code, void *closure)
19191842
}
19201843

19211844
staticPyGetSetDefcode_getsetlist[]= {
1922-
{"co_lnotab", (getter)code_getlnotab,NULL,NULL},
19231845
{"_co_code_adaptive", (getter)code_getcodeadaptive,NULL,NULL},
19241846
// The following old names are kept for backward compatibility.
19251847
{"co_varnames", (getter)code_getvarnames,NULL,NULL},

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp