[issue21217] inspect.getsourcelines finds wrong lines when lambda used argument to decorator

A Kaptur report at bugs.python.org
Tue Apr 15 00:49:51 CEST 2014


A Kaptur added the comment:

This patch adds tests demonstrating broken behavior inspect.getsource and inspect.getsourcelines of decorators containing lambda functions, and modifies inspect.getsourcelines to behave correctly.

We use co_lnotab to extract line numbers on all objects with a code object. inspect.getsourcelines can also take a class, which cannot use co_lnotab as there is no associated code object.

@ballingt and I paired on this patch.

Some open questions about inspect.getsource not created or addressed by this patch:
- Is this a bug that should be patched in previous versions as well?
- the docs for say it can take a traceback. What is the correct behavior here?  There aren't any tests at the moment. We suggest the line of code that caused the traceback, i.e. the line at tb.tb_lineno
-  We added tests of decorated classes. The source of decorated classes does not include the decorators, which is different than the usual behavior of decorated functions. What is the correct behavior here?
- inspect.getblock and inspect.BlockFinder use the term "block" in a way that is inconsistent with its typical use in the interpreter (that is, in ceval.c). Should this be renamed? If so, to what? ("chunk"?)

----------
keywords: +patch
nosy: +akaptur
stage:  -> patch review
versions:  -Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4
Added file: http://bugs.python.org/file34857/issue21217.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21217>
_______________________________________


More information about the Python-bugs-list mailing list