[Python-Dev] PEP 362 minor nits (original) (raw)

Nick Coghlan ncoghlan at gmail.com
Wed Jun 20 13:54:46 CEST 2012


On Wed, Jun 20, 2012 at 6:30 PM, Steven D'Aprano <steve at pearwood.info> wrote:

Speaking of non-instance method descriptors, please excuse this silly question, I haven't quite understood the implementation well enough to answer this question myself. Is there anything needed to make signature() work correctly with custom method-like descriptors such as this?

http://code.activestate.com/recipes/577030-dualmethod-descriptor

They're odd enough that they would probably need to implement signature as a property (or custom descriptor) and construct the appropriate signature on the fly. However, that's only necessary if you wanted to support passing the descriptor directly to inspect.signature.

The result of Example.method or Example().method would be an ordinary function, which would delegate to signature(self.func) by default (thanks to the use of functools.wraps).

To account for the hidden argument correctly, you would actually want to set a custom signature that dropped the first parameter.

Cheers, Nick.

-- Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia



More information about the Python-Dev mailing list