[issue20009] Property should expose wrapped function.

steven Michalske report at bugs.python.org
Tue Dec 17 22:49:55 CET 2013


New submission from steven Michalske:

When using the @property decorator the wrapped functions are not exposed for source introspection. (At least I can't see how they are.)

The issue is then that Ipython "%psource" will show the source for the @property as opposed to the function that it wraps.

By implementing the __wrapped__ attribute you can set the wrapped function to fget and then the source for that function can me identified for source introspection.

I perform this hack in code to overcome this issue.

class qproperty(property):
    # Fix for ipython ? and ?? (%pdef, %psource)
    # Omitting the class doc string prevents ipython from showing the
    # doctoring for the property builtin class; I suspect this is a
    # bug.
    def __init__(self, fget=None, fset=None, fdel=None, doc=None):
        super(qproperty, self).__init__(fget, fset, fdel, doc)
        self.__wrapped__ = fget

# Overwrite property with qproperty so that in the future this hack might
# be easily removed.
property = qproperty

This is related to issue #5982.

----------
messages: 206483
nosy: hardkrash
priority: normal
severity: normal
status: open
title: Property should expose wrapped function.
type: enhancement
versions: Python 3.4, Python 3.5

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


More information about the Python-bugs-list mailing list