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

2015-07-23 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 5400e21e92a7 by Meador Inge in branch '3.5':
Issue #24485: Function source inspection fails on closures.
https://hg.python.org/cpython/rev/5400e21e92a7

New changeset 0e7d64595223 by Meador Inge in branch 'default':
Issue #24485: Function source inspection fails on closures.
https://hg.python.org/cpython/rev/0e7d64595223

--

___
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



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

2015-07-23 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 4e42a62d5648 by Yury Selivanov in branch '3.5':
Issue #24485: Revert backwards compatibility breaking changes of #21217.
https://hg.python.org/cpython/rev/4e42a62d5648

New changeset 98a2bbf2cce2 by Yury Selivanov in branch 'default':
Merge 3.5 (issues #21217, #24485).
https://hg.python.org/cpython/rev/98a2bbf2cce2

--

___
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



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

2015-06-28 Thread Meador Inge

Meador Inge added the comment:

FYI, I posted a patch to handle this case and the regression
noted in issue24485 on issue24485.

--

___
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



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

2015-06-26 Thread Terry J. Reedy

Terry J. Reedy added the comment:

I strongly suspect that ac86e5b2d45b is the cause of the regression reported in 
#24485. 

def outer():
def inner():
inner1
from inspect import getsource
print(getsource(outer))

omits the body of inner.  Ditto if outer is a method.  All is okay if outer is 
a method and the source of the class is requested.

Could the authors, Allison and Thomas, take a look and try to fix 
_line_number_helper to pass the added test (and possibly incorporate it into 
findsource)?  Since there is a new issue already, this one can be left closed 
and further work posted to #24485.

--
nosy: +terry.reedy

___
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



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

2015-06-26 Thread Meador Inge

Meador Inge added the comment:

 I think that the only way we can solve this is to revert the patch for this 
 issue.

I agree with this.  It seems like doing this analysis at the bytecode level is 
the
wrong approach.  Perhaps the syntactical analysis being used before should be 
beefed
up to handle things like the lambda case.

--
nosy: +meador.inge

___
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



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

2015-06-26 Thread Yury Selivanov

Yury Selivanov added the comment:

Here's an update on #24485 regression.

Looks like getsource() is now using code objects instead of tokenizer to 
determine blocks first/last lines.

The problem with this particular case is that inner function's code object is 
completely independent from outer's.

So, for an outer() function below:

def outer():
def inner():
never_reached1
never_reached2

the code object contains the following opcodes:

 71   0 LOAD_CONST   1 (code object inner ...)
  3 LOAD_CONST   2 ('outer1.locals.inner')
  6 MAKE_FUNCTION0
  9 STORE_FAST   0 (inner)
 12 LOAD_CONST   0 (None)
 15 RETURN_VALUE

The correct solution is to use co_lnotab along with co_firstlineno to iterate 
through opcodes recursively accounting for MAKE_FUNCTION's code objects.

*However*, I don't think we can solve this for classes, i.e.

def outer_with_class():
   class Foo:
  b = 1
  a = 2

there is no way (as far as I know) to get information about the Foo class 
start/end lineno.

I think that the only way we can solve this is to revert the patch for this 
issue.

--

___
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



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

2015-04-14 Thread Thomas Ballinger

Thomas Ballinger added the comment:

Thanks Antoine! Could you add Allison Kaptur to NEWS and ACKS? This was an 
update to her original patch, and we paired on the whole thing.

--

___
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



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

2015-04-14 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 582e8e71f635 by Benjamin Peterson in branch 'default':
add Allison Kaptur (#21217)
https://hg.python.org/cpython/rev/582e8e71f635

--

___
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



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

2015-04-14 Thread Antoine Pitrou

Antoine Pitrou added the comment:

I've committed the latest patch. Thank you, Thomas!

--
resolution:  - fixed
stage: patch review - resolved
status: open - closed

___
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



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

2015-04-14 Thread Roundup Robot

Roundup Robot added the comment:

New changeset ac86e5b2d45b by Antoine Pitrou in branch 'default':
Issue #21217: inspect.getsourcelines() now tries to compute the start and
https://hg.python.org/cpython/rev/ac86e5b2d45b

--
nosy: +python-dev

___
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



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

2015-04-13 Thread Thomas Ballinger

Thomas Ballinger added the comment:

Use dis.findlinestarts() to find lines of function instead of grubbing with 
co_lnotab manually, making dis module dependency non-optional.

--
Added file: http://bugs.python.org/file38970/issue21217-v6.patch

___
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



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

2015-04-13 Thread Antoine Pitrou

Changes by Antoine Pitrou pit...@free.fr:


--
nosy: +pitrou

___
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



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

2015-04-13 Thread Thomas Ballinger

Thomas Ballinger added the comment:

v4 of patch, with tests updated for changed lines in inspect fodder file

--
Added file: http://bugs.python.org/file38959/issue21217-v4.patch

___
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



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

2015-04-13 Thread Nick Coghlan

Nick Coghlan added the comment:

It sounds like at least a somewhat functional dis module is a pragmatic 
requirement for a Python implementation to support introspection, so +1 for 
reverting to the mandatory dependency on dis rather than duplicating its logic.

--
nosy: +ncoghlan

___
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



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

2015-04-13 Thread Thomas Ballinger

Thomas Ballinger added the comment:

Patch reformatted to be non-git style, NEWS item removed

--
Added file: http://bugs.python.org/file38965/issue21217-v5.patch

___
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



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

2014-04-15 Thread A Kaptur

A Kaptur added the comment:

v2 of the patch incorporating the comments at 
http://bugs.python.org/review/21217/

--
Added file: http://bugs.python.org/file34882/issue21217-v2.patch

___
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



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

2014-04-15 Thread Yury Selivanov

Yury Selivanov added the comment:

Apart from one nit, the patch is looking good.

Also, could you please sign the contributor agreement, as described here: 
https://docs.python.org/devguide/coredev.html#sign-a-contributor-agreement

--

___
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



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

2014-04-15 Thread Claudiu.Popa

Claudiu.Popa added the comment:

-  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?


There is an open issue for this, http://bugs.python.org/issue1764286. It has a 
patch which uses inspect.unwrap in order to unwrap the decorated functions.

--
nosy: +Claudiu.Popa

___
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



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

2014-04-15 Thread Yury Selivanov

Yury Selivanov added the comment:

Claudiu: I'll take a look at your patch, thanks!

--

___
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



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

2014-04-15 Thread A Kaptur

A Kaptur added the comment:

v3 of patch, including misc/news update, docstring for function, and removing 
class decorator tests, since it sounds like those are better handled in 
http://bugs.python.org/issue1764286.

--
Added file: http://bugs.python.org/file34885/issue21217-v3.patch

___
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



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

2014-04-14 Thread Thomas Ballinger

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



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

2014-04-14 Thread Thomas Ballinger

Thomas Ballinger added the comment:

The code object's co_lnotab is how inspect should be getting the sourcelines 
of the code, instead of looking for the first codeblock.

I'm looking at this now, thanks to Yhg1s for the above.

--

___
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



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

2014-04-14 Thread Yury Selivanov

Changes by Yury Selivanov yselivanov...@gmail.com:


--
nosy: +yselivanov

___
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



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

2014-04-14 Thread A Kaptur

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 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