Created
April 14, 2014 17:08
-
-
Save thomasballinger/10666031 to your computer and use it in GitHub Desktop.
Possible bug in inspect.getsourcelines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment