[issue35101] inspect.findsource breaks on class frame objects

orlnub123 report at bugs.python.org
Mon Oct 29 00:17:50 EDT 2018


New submission from orlnub123 <orlnub123 at gmail.com>:

If you pass a frame object belonging to a class into findsource, it'll incorrectly give you the starting line number of the first function above it or 0 if no functions are defined.

Here's some code to reproduce the issue:

import inspect

def test_func():
    ...  # This should not get printed

class Test:
    frame = inspect.currentframe()

print(inspect.getsource(Test.frame))  # Depends on findsource

This unexpectedly prints the source of test_func instead of the class right below it.

----------
components: Library (Lib)
messages: 328788
nosy: orlnub123
priority: normal
severity: normal
status: open
title: inspect.findsource breaks on class frame objects
type: behavior
versions: Python 3.6, Python 3.7, Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35101>
_______________________________________


More information about the Python-bugs-list mailing list