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

Reply via email to