From 9709e1d9d76f13802e8f967c25d9887a500272ae Mon Sep 17 00:00:00 2001 From: Himesh Rupchandani Date: Fri, 23 Oct 2026 23:13:47 +0530 Subject: [PATCH] gh-156725: Document O(N) behavior of `PyCode_Addr2Line` (GH-156736) (cherry picked from commit 8d119208074fef0f652f14f78612b044dd218c4f) Co-authored-by: Himesh Rupchandani --- Doc/c-api/code.rst | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Doc/c-api/code.rst b/Doc/c-api/code.rst index b34edb409da9a8..96104017da5975 100644 --- a/Doc/c-api/code.rst +++ b/Doc/c-api/code.rst @@ -94,11 +94,12 @@ bound into a function. .. c:function:: int PyCode_Addr2Line(PyCodeObject *co, int byte_offset) - Return the line number of the instruction that occurs on or before ``byte_offset`` and ends after it. - If you just need the line number of a frame, use :c:func:`PyFrame_GetLineNumber` instead. + Return the line number of the instruction that occurs on or before + ``byte_offset`` and ends after it. This may be ``O(N)`` in the number of + instructions in the code object, so it is not performant for iterating over + all the line numbers in a code object. - For efficiently iterating over the line numbers in a code object, use :pep:`the API described in PEP 626 - <0626#out-of-process-debuggers-and-profilers>`. + If you just need the line number of a frame, use :c:func:`PyFrame_GetLineNumber` instead. .. c:function:: int PyCode_Addr2Location(PyObject *co, int byte_offset, int *start_line, int *start_column, int *end_line, int *end_column)