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 skip.montanaro
Recipients skip.montanaro
Date 2017-04-21.14:27:50
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
I needed to create a partial method in Python 2.7, so I grabbed functools.partialmethod from a Python 3.5.2 install. For various reasons, one of the reasons I wanted this was to suck in some methods from a delegated class so they appeared in dir() and help() output on the primary class (the one containing the partialmethod objects). Suppose I have

class Something:
  def meth(self, arg1, arg2):
    "meth doc"
    return arg1 + arg2

then in the metaclass for another class I construct an attribute (call it "mymeth") which is a partialmethod object. When I (for example), run pydoc, that other class's attribute appears as:

    mymeth = <functools.partial object>

It would be nice if it at least included the doc string from meth, something like:

    mymeth = <functools.partial object>
        meth doc

Even better would be a proper signature:

    mymeth(self, arg1, arg2)
        meth doc

In my copy of functools.partialmethod, I inserted an extra line in __get__, right after the call to partial():

    results.__doc__ = self.func.__doc__

That helps a bit, as I can

    print("mymeth doc:", inst.mymeth.__doc__)

and see

    mymeth doc: meth doc

displayed. That's not enough for help()/pydoc though.

I suspect the heavy lifting will have to be done in pydoc.Doc.document(). inspect.isroutine() returns False for functools.partial objects. I also see _signature_get_partial() in That might be the source of the problem. When I create a partialmethod object in my little example, it actually looks like a functools.partial object, not a partialmethod object. It's not clear that this test:

    if isinstance(partialmethod, functools.partialmethod):

in inspect._signature_from_callable() is testing for the correct type.

Apologies that I can't easily provide a detailed example. My Python 2.x metaclass example (where I'm smashing methods from one class into another) doesn't work in Python 3.x for some reason, the whole partialmethod thing isn't available in Python 2.x (inspect doesn't know about partialmethod or partial) and it's not really a "hello world"-sized example anyway. I'll beat on things a bit more to try and craft a workable Python 3.x example.
Date User Action Args
2017-04-21 14:27:51skip.montanarosetrecipients: + skip.montanaro
2017-04-21 14:27:51skip.montanarosetmessageid: <>
2017-04-21 14:27:50skip.montanarolinkissue30129 messages
2017-04-21 14:27:50skip.montanarocreate