New submission from Thomas Ballinger:

https://gist.github.com/thomasballinger/10666031

"""
inspect.getsourcelines incorrectly guesses what lines correspond
to the function foo
 
see getblock in inspect.py
once it finds a lambda, def or class it finishes it then stops
so get getsourcelines returns only the first two noop decorator
lines of bar, while normal behavior is to return all decorators
as it does for foo
"""
import inspect
from pprint import pprint
 
def noop(arg):
    def inner(func):
        return func
    return inner
 
@noop(1)
@noop(2)
def foo():
    return 1
 
@noop(1)
@noop(lambda: None)
@noop(1)
def bar():
    return 1
 
pprint(inspect.getsourcelines(foo))
pprint(inspect.getsourcelines(bar))

----------
components: Library (Lib)
messages: 216127
nosy: ballingt
priority: normal
severity: normal
status: open
title: inspect.getsourcelines finds wrong lines when lambda used argument to 
decorator
type: behavior
versions: Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4, Python 3.5

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue21217>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to