Skip to content

Instantly share code, notes, and snippets.

@thomasballinger
Created April 14, 2014 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasballinger/10666031 to your computer and use it in GitHub Desktop.
Save thomasballinger/10666031 to your computer and use it in GitHub Desktop.
Possible bug in inspect.getsourcelines
"""
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