[issue1764286] inspect.getsource does not work with decorated functions

2018-08-02 Thread Eric Wieser


Eric Wieser  added the comment:

New issue opened at https://bugs.python.org/issue34305, along with a PR linked 
there.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1764286] inspect.getsource does not work with decorated functions

2018-07-31 Thread Yury Selivanov


Yury Selivanov  added the comment:

> Should `getsourcefile` be changed to match?

I'd say yes. There's no point in getsourcefile returning the file location of 
the topmost decorator. Feel free to open a new issue and submit a PR to fix 
this!

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1764286] inspect.getsource does not work with decorated functions

2018-07-31 Thread Eric Wieser


Eric Wieser  added the comment:

This now leaves `inspect.getsource` inconsistent with `inspect.getsourcefile`:

>>> import inspect
>>> from contextlib import contextmanager

>>> @contextmanager
... def func():
...yield

>>> inspect.getsource(func)
'@contextmanager\ndef func():\nyield\n'
>>>inspect.getsourcefile(func)
'C:\\Program Files\\Python 3.5\\lib\\contextlib.py'

Should `getsourcefile` be changed to match?

This is causing numpy/numpy#11639, but it's not clear if this is a bug or by 
design.

--
nosy: +Eric.Wieser

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1764286] inspect.getsource does not work with decorated functions

2014-09-26 Thread Roundup Robot

Roundup Robot added the comment:

New changeset ad9cc6124a19 by Yury Selivanov in branch 'default':
inspect: Fix getsource() to support decorated functions.
https://hg.python.org/cpython/rev/ad9cc6124a19

--
nosy: +python-dev

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1764286
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1764286] inspect.getsource does not work with decorated functions

2014-09-26 Thread Yury Selivanov

Yury Selivanov added the comment:

Thanks for the bug report and patch! Committed to 3.5.

--
resolution:  - fixed
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1764286
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1764286] inspect.getsource does not work with decorated functions

2014-09-26 Thread Berker Peksag

Changes by Berker Peksag berker.pek...@gmail.com:


--
stage: patch review - resolved

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1764286
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1764286] inspect.getsource does not work with decorated functions

2014-08-25 Thread Claudiu Popa

Changes by Claudiu Popa pcmantic...@gmail.com:


--
stage: test needed - patch review

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1764286
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1764286] inspect.getsource does not work with decorated functions

2014-04-15 Thread Yury Selivanov

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


--
assignee:  - yselivanov

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1764286
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1764286] inspect.getsource does not work with decorated functions

2014-01-28 Thread Yury Selivanov

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


--
nosy: +yselivanov
versions: +Python 3.5 -Python 2.7, Python 3.2, Python 3.3, Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1764286
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1764286] inspect.getsource does not work with decorated functions

2013-09-29 Thread Claudiu.Popa

Claudiu.Popa added the comment:

Hello. Attached patch which uses the new inspect.unwrap, added in 
http://hg.python.org/cpython/rev/2aa6c1e35b8a.

--
keywords: +patch
nosy: +Claudiu.Popa
Added file: http://bugs.python.org/file31902/inspect_getsource.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1764286
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1764286] inspect.getsource does not work with decorated functions

2013-08-04 Thread Alexander Belopolsky

Changes by Alexander Belopolsky alexander.belopol...@gmail.com:


--
assignee: belopolsky - 

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1764286
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1764286] inspect.getsource does not work with decorated functions

2013-01-27 Thread Ezio Melotti

Changes by Ezio Melotti ezio.melo...@gmail.com:


--
versions: +Python 3.3, Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1764286
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1764286] inspect.getsource does not work with decorated functions

2010-07-19 Thread Ray.Allen

Ray.Allen ysj@gmail.com added the comment:

I don't think this patch is correct, because we don't know if the closure[0] is 
the wrapped function, consider the following case:

def fun():
abc = 1
def fun2():
print(abc)
print(inspect.getsource(fun2))

In this case, the __closure__ of fun2 is [cell(1), ], the patch doesn't work.


I think the behavior of inspect.getsource(arg) is no problem because it indeed 
gives the right source code of arg, no matter arg is a wrapper function or an 
original function. michele argues that the result is not meaningful, through in 
most case it seems reasonably because wrapper functions usually do litter 
valuable work, but it is not correct for all cases. What if a wrapper function 
does more valuable work than the wrapped function? In this case should 
getsouce() give the source code of wrapper function because it's more 
meaningful? The concept wrapper and wrapped should have no relation with 
its source code.

I suggest you assign a special named attribute of all wrapper functions to its 
wrapped function yourself, something like wrapped_function, and then you can 
walk through the wrapper chain to find the real source you want for each 
wrapper function. Then the stdard library's update_wrapper() and getsource() 
can remain unchanged.

--
nosy: +ysj.ray

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1764286
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1764286] inspect.getsource does not work with decorated functions

2010-07-18 Thread Alexander Belopolsky

Alexander Belopolsky belopol...@users.sourceforge.net added the comment:

I did not test the patch, but if it really addresses the issue, I don't see why 
such a simple fix would not be applied.  


Guilherme,

Can you add unit tests? Also, the second chunk in your patch is just a style 
fix which is a distraction for reviewers.

--
assignee:  - belopolsky
nosy: +belopolsky
stage:  - unit test needed
type:  - behavior
versions: +Python 2.7, Python 3.2 -Python 2.6, Python 3.0

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1764286
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1764286] inspect.getsource does not work with decorated functions

2008-02-07 Thread Guilherme Polo

Guilherme Polo added the comment:

I am attaching a patch that address this issue.

--
nosy: +gpolo
Added file: http://bugs.python.org/file9384/inspect.py.diff

_
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1764286
_
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1764286] inspect.getsource does not work with decorated functions

2008-01-17 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Rather than devising something specific to the co_firstlineno attribute,
why not have functools.update_wrapper add a wrapped_func attribute
pointing to the original function object? That way, each function
inspecting the decorated function would have the opportunity to walk the
decoration chain if it wants.

--
nosy: +pitrou

_
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1764286
_
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com