New submission from orlnub123 <orlnub...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue35101>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to