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

gh-134690: Removed deprecatedcodetype.co_lnotab#134691

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
sobolevn wants to merge2 commits intopython:main
base:main
Choose a base branch
Loading
fromsobolevn:issue-134690
Open
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
NextNext commit
gh-134690: Removed deprecatedcodetype.co_lnotab
  • Loading branch information
@sobolevn
sobolevn committedMay 26, 2025
commitf892097e39af13c36020db6a10561a31d0898e22
2 changes: 1 addition & 1 deletionDoc/deprecations/pending-removal-in-3.15.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -70,7 +70,7 @@ Pending removal in Python 3.15

* :mod:`types`:

* :class:`types.CodeType`: Accessing :attr:`~codeobject.co_lnotab` was
* :class:`types.CodeType`: Accessing :attr:`!codeobject.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.
Expand Down
2 changes: 1 addition & 1 deletionDoc/deprecations/pending-removal-in-future.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -49,7 +49,7 @@ although there is currently no date scheduled for their removal.

* :mod:`codecs`: use :func:`open` instead of :func:`codecs.open`. (:gh:`133038`)

* :attr:`codeobject.co_lnotab`: use the :meth:`codeobject.co_lines` method
* :attr:`!codeobject.co_lnotab`: use the :meth:`codeobject.co_lines` method
instead.

* :mod:`datetime`:
Expand Down
2 changes: 1 addition & 1 deletionDoc/library/dis.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -400,7 +400,7 @@ operation is being performed, so the intermediate analysis object isn't useful:

.. versionchanged:: 3.10
The :pep:`626` :meth:`~codeobject.co_lines` method is used instead of the
:attr:`~codeobject.co_firstlineno` and :attr:`~codeobject.co_lnotab`
:attr:`~codeobject.co_firstlineno` and :attr:`!codeobject.co_lnotab`
attributes of the :ref:`code object <code-objects>`.

.. versionchanged:: 3.13
Expand Down
4 changes: 0 additions & 4 deletionsDoc/library/inspect.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -198,10 +198,6 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
| | | read more :ref:`here |
| | | <inspect-module-co-flags>`|
+-----------------+-------------------+---------------------------+
| | co_lnotab | encoded mapping of line |
| | | numbers to bytecode |
| | | indices |
+-----------------+-------------------+---------------------------+
| | co_freevars | tuple of names of free |
| | | variables (referenced via |
| | | a function's closure) |
Expand Down
9 changes: 0 additions & 9 deletionsDoc/reference/datamodel.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1415,7 +1415,6 @@ indirectly) to mutable objects.
single: co_filename (code object attribute)
single: co_firstlineno (code object attribute)
single: co_flags (code object attribute)
single: co_lnotab (code object attribute)
single: co_name (code object attribute)
single: co_names (code object attribute)
single: co_nlocals (code object attribute)
Expand DownExpand Up@@ -1488,14 +1487,6 @@ Special read-only attributes
* - .. attribute:: codeobject.co_firstlineno
- The line number of the first line of the function

* - .. attribute:: codeobject.co_lnotab
- A string encoding the mapping from :term:`bytecode` offsets to line
numbers. For details, see the source code of the interpreter.

.. deprecated:: 3.12
This attribute of code objects is deprecated, and may be removed in
Python 3.15.

* - .. attribute:: codeobject.co_stacksize
- The required stack size of the code object

Expand Down
2 changes: 1 addition & 1 deletionDoc/whatsnew/3.10.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -402,7 +402,7 @@ Tracing events, with the correct line number, are generated for all lines of cod
The :attr:`~frame.f_lineno` attribute of frame objects will always contain the
expected line number.

The :attr:`~codeobject.co_lnotab` attribute of
The :attr:`!codeobject.co_lnotab` attribute of
:ref:`code objects <code-objects>` is deprecated and
will be removed in 3.12.
Code that needs to convert from offset to line number should use the new
Expand Down
2 changes: 1 addition & 1 deletionDoc/whatsnew/3.12.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1333,7 +1333,7 @@ Deprecated
``int``, convert to int explicitly: ``~int(x)``. (Contributed by Tim Hoffmann
in :gh:`103487`.)

* Accessing :attr:`~codeobject.co_lnotab` on code objects was deprecated in
* Accessing :attr:`!codeobject.co_lnotab` on code objects was deprecated in
Python 3.10 via :pep:`626`,
but it only got a proper :exc:`DeprecationWarning` in 3.12.
May be removed in 3.15.
Expand Down
8 changes: 8 additions & 0 deletionsDoc/whatsnew/3.15.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -154,6 +154,14 @@ threading
(Contributed by Bénédikt Tran in :gh:`134087`.)


types
-----

* Removed deprecated in :pep:`626` since Python 3.12
:attr:`!codeobject.co_lnotab` from :class:`types.CodeType`.
(Contributed by Nikita Sobolev in :gh:`134690`.)


typing
------

Expand Down
2 changes: 1 addition & 1 deletionDoc/whatsnew/3.6.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2173,7 +2173,7 @@ Changes in the Python API
* :c:func:`PyErr_SetImportError` now sets :exc:`TypeError` when its **msg**
argument is not set. Previously only ``NULL`` was returned.

* The format of the :attr:`~codeobject.co_lnotab` attribute of code objects
* The format of the :attr:`!codeobject.co_lnotab` attribute of code objects
changed to support
a negative line number delta. By default, Python does not emit bytecode with
a negative line number delta. Functions using :attr:`frame.f_lineno`,
Expand Down
8 changes: 0 additions & 8 deletionsInternalDocs/code_objects.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -70,14 +70,6 @@ The `co_linetable` bytes object of code objects contains a compact
representation of the source code positions of instructions, which are
returned by the `co_positions()` iterator.

> [!NOTE]
> `co_linetable` is not to be confused with `co_lnotab`.
> For backwards compatibility, `co_lnotab` exposes the format
> as it existed in Python 3.10 and lower: this older format
> stores only the start line for each instruction.
> It is lazily created from `co_linetable` when accessed.
> See [`Objects/lnotab_notes.txt`](../Objects/lnotab_notes.txt) for more details.

`co_linetable` consists of a sequence of location entries.
Each entry starts with a byte with the most significant bit set, followed by
zero or more bytes with the most significant bit unset.
Expand Down
2 changes: 0 additions & 2 deletionsLib/inspect.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -415,7 +415,6 @@ def iscode(object):
co_freevars tuple of names of free variables
co_posonlyargcount number of positional only arguments
co_kwonlyargcount number of keyword only arguments (not including ** arg)
co_lnotab encoded mapping of line numbers to bytecode indices
co_name name with which this code object was defined
co_names tuple of names other than arguments and function locals
co_nlocals number of local variables
Expand DownExpand Up@@ -1604,7 +1603,6 @@ def getframeinfo(frame, context=1):

def getlineno(frame):
"""Get the line number from a frame object, allowing for optimization."""
# FrameType.f_lineno is now a descriptor that grovels co_lnotab
return frame.f_lineno

_FrameInfo = namedtuple('_FrameInfo', ('frame',) + Traceback._fields)
Expand Down
7 changes: 0 additions & 7 deletionsLib/test/test_code.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -424,13 +424,6 @@ 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

@unittest.skipIf(_testinternalcapi is None, '_testinternalcapi is missing')
def test_returns_only_none(self):
value = True
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
Removed deprecated in :pep:`626` since Python 3.12
:attr:`!codeobject.co_lnotab` from :class:`types.CodeType`.
13 changes: 0 additions & 13 deletionsObjects/codeobject.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1318,7 +1318,7 @@
}

static PyObject *
decode_linetable(PyCodeObject *code)

Check warning on line 1321 in Objects/codeobject.c

View workflow job for this annotation

GitHub Actions/ Ubuntu / build and test (ubuntu-24.04)

‘decode_linetable’ defined but not used [-Wunused-function]

Check warning on line 1321 in Objects/codeobject.c

View workflow job for this annotation

GitHub Actions/ Cross build Linux

‘decode_linetable’ defined but not used [-Wunused-function]

Check warning on line 1321 in Objects/codeobject.c

View workflow job for this annotation

GitHub Actions/ Hypothesis tests on Ubuntu

‘decode_linetable’ defined but not used [-Wunused-function]

Check warning on line 1321 in Objects/codeobject.c

View workflow job for this annotation

GitHub Actions/ Ubuntu / build and test (ubuntu-24.04)

‘decode_linetable’ defined but not used [-Wunused-function]

Check warning on line 1321 in Objects/codeobject.c

View workflow job for this annotation

GitHub Actions/ Ubuntu / build and test (ubuntu-24.04-arm)

‘decode_linetable’ defined but not used [-Wunused-function]

Check warning on line 1321 in Objects/codeobject.c

View workflow job for this annotation

GitHub Actions/ Cross build Linux

‘decode_linetable’ defined but not used [-Wunused-function]

Check warning on line 1321 in Objects/codeobject.c

View workflow job for this annotation

GitHub Actions/ Address sanitizer (ubuntu-24.04)

‘decode_linetable’ defined but not used [-Wunused-function]

Check warning on line 1321 in Objects/codeobject.c

View workflow job for this annotation

GitHub Actions/ Ubuntu (free-threading) / build and test (ubuntu-24.04-arm)

‘decode_linetable’ defined but not used [-Wunused-function]

Check warning on line 1321 in Objects/codeobject.c

View workflow job for this annotation

GitHub Actions/ Ubuntu (free-threading) / build and test (ubuntu-24.04)

‘decode_linetable’ defined but not used [-Wunused-function]
{
PyCodeAddressRange bounds;
PyObject *bytes;
Expand DownExpand Up@@ -2617,18 +2617,6 @@
};


static PyObject *
code_getlnotab(PyObject *self, void *closure)
{
PyCodeObject *code = _PyCodeObject_CAST(self);
if (PyErr_WarnEx(PyExc_DeprecationWarning,
"co_lnotab is deprecated, use co_lines instead.",
1) < 0) {
return NULL;
}
return decode_linetable(code);
}

static PyObject *
code_getvarnames(PyObject *self, void *closure)
{
Expand DownExpand Up@@ -2666,7 +2654,6 @@
}

static PyGetSetDef code_getsetlist[] = {
{"co_lnotab", code_getlnotab, NULL, NULL},
{"_co_code_adaptive", code_getcodeadaptive, NULL, NULL},
// The following old names are kept for backward compatibility.
{"co_varnames", code_getvarnames, NULL, NULL},
Expand Down
Loading
Loading

[8]ページ先頭

©2009-2025 Movatter.jp