This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: inspect.getframeinfo bug if 'context' is to big
Type: Stage:
Components: Library (Lib) Versions: Python 2.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: krauthae, rhettinger
Priority: normal Keywords:

Created on 2004-06-15 09:09 by krauthae, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg21195 - (view) Author: Hans Georg Krauthaeuser (krauthae) Date: 2004-06-15 09:09
In inspect.getframeinfo index gets wrong if context is
larger than len(lines).

the lines are:
...
    if context > 0:
        start = lineno - 1 - context//2
        try:
            lines, lnum = findsource(frame)
        except IOError:
            lines = index = None
        else:
            start = max(start, 1)
            start = min(start, len(lines) - context)
            ^^^^^^^^^^^^^^^^^^^^^^^^
            lines = lines[start:start+context]
            index = lineno - 1 - start
    else:
        lines = index = None
...

The 'min' statement gives a negative start if context
is to large. As a result index gets to large.

The solution is just to put

context = min(context,len(lines))

after the first 'else:'

Regards
msg21196 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2004-06-15 11:23
Logged In: YES 
user_id=80475

Fixed.  See Lib/inspect.py 1.51
History
Date User Action Args
2022-04-11 14:56:04adminsetgithub: 40402
2004-06-15 09:09:52krauthaecreate