This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ysj.ray
Recipients belopolsky, christian.heimes, gpolo, michele_s, pitrou, ysj.ray
Date 2010-07-19.13:40:56
SpamBayes Score 0.00035256697
Marked as misclassified No
Message-id <1279546859.32.0.459185883392.issue1764286@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2010-07-19 13:40:59ysj.raysetrecipients: + ysj.ray, michele_s, belopolsky, pitrou, christian.heimes, gpolo
2010-07-19 13:40:59ysj.raysetmessageid: <1279546859.32.0.459185883392.issue1764286@psf.upfronthosting.co.za>
2010-07-19 13:40:57ysj.raylinkissue1764286 messages
2010-07-19 13:40:56ysj.raycreate