guido van rossum hoaufpythonorg would mind giving executive summary argument doesnt require scanning 40 lines code thu mar 6 2008 743 pm anthony tolle wrote exhibit wraptestpy demonstrates using wrapper insert extra argument method calls import sys sysversion_info0 3 _self_attr im_self else _self_attr __self__ class methodwrapperobject def __init__self descriptor callablenone selfdescriptor descriptor selfcallable callable def __get__self obj typenone selfcallable none return self return methodwrapperselfdescriptor selfdescriptor__get__obj type def __call__self args kwargs selfcallable none raise typeerrorwrapper called __get__ try obj getattrselfcallable _self_attr except attributeerror must function return selfcallable__call__inserted args kwargs obj none must unbound method args raise typeerrorinstance argument missing return selfcallable__call__args0 inserted args1 kwargs must bound method return selfcallable__call__inserted args kwargs __name__ __main__ class aobject methodwrapper staticmethod def sinserted return inserted methodwrapper classmethod def ccls inserted return inserted methodwrapper def iself inserted return inserted assert inserted instance binding static method assert ac inserted instance binding class method assert ai inserted instance binding instance method assert inserted class binding static method assert ac inserted class binding class method assert aia inserted class binding instance method exhibit b run wraptestpy python 25 assertions pass however run python 30 witness traceback recent call last file wraptestpy line 64 assert aia inserted class binding instance method assertionerror summary subtle difference unbound method function generally one assume underlying function unbound method expect instance first argument case plain functions heres 1 staticmethod descriptor always returns function arguments passed implicitly 2 classmethod descriptor always returns bound method implicitly passes instance class first argument underlying function 3 leaves regular instance methods version 25 descriptor return either bound method instance argument passed implicitly unbound method instance argument must passed explicitly depending binding used instance binding class binding respectively either way underlying function expect instance first argument table combinations python 25 using wraptestpy template staticmethod descriptor function im_self attribute ac classmethod descriptor bound method im_self ai function descriptor bound method im_self staticmethod descriptor function im_self attribute ac classmethod descriptor bound method im_self ai function descriptor unbound method im_self none creating custom descriptor needs wrap static methods class methods instance methods one determine difference instance binding class binding instance methods whether descriptor returns bound method unbound method however 30 unbound methods done away situation follows staticmethod descriptor function __self__ attribute ac classmethod descriptor bound method __self__ ai function descriptor bound method __self__ staticmethod descriptor function __self__ attribute ac classmethod descriptor bound method __self__ ai function descriptor function __self__ attribute wrapper receives function descriptor know static method doesnt need instance argument instance method class binding ok suppose code could check descriptor instance staticmethod classmethod however slower duck typing used example code assuming majority methods plain instance methods using duck typing class wrap descriptors might mimic classmethod staticmethod code could even extended mimicking behavior underlying descriptor essentially masking presence way several wrappers could chained together without check type descriptor another solution would create two separate wrappers one static methods one class methods instance methods however seems clumsy since isnt even necessary 25 made case existence unbound methods dont know ill first admit may missed something vitally important analysis perhaps new way things 30 strive perhaps hung creating universal method wrapper anyway thoughts subject thanks time anthony tolle _______________________________________________ python3000 mailing list smsbmo9552pythonorg httpmailpythonorgmailmanlistinfopython3000 unsubscribe httpmailpythonorgmailmanoptionspython3000guido40pythonorg guido van rossum home page httpwwwpythonorgguido _______________________________________________ python3000 mailing list smsbmo9552pythonorg httpmailpythonorgmailmanlistinfopython3000 unsubscribe httpmailpythonorgmailmanoptionspython3000python300040tangomucom tue 05 aug 2008 204755 0800 python3000 case unbound methods