text_combined: nick coghlan uytankmfgmailcom guido van rossum wrote wed apr 2 2008 630 nick coghlan wrote one issues porting py3k problem __getattr__ __getattribute__ cant reliably provide special methods like __add__ way __getattr__ could classic classes first noted terry reedy years ago recently seeing new activity bug tracker 1 culprit fact __getattribute__ associated machinery typically never invoked methods dedicated tp_ slots clevel type structure well yes intentional part newstyle class design complaining trying provide background may quite familiar inner workings typeobjectc people think idea providing extra method type objects goes clevel special method slots one isnt currently set getattr associated special name stores result current type object getattr since seem thinking specifically proxies im thinking youre getattr instance seems wrong base type slots doh youre right specific proxying example thinking see indeed grab bound methods directly underlying instance however think idea salvageable whether worth salvaging course completely different question converting proxy class relies __getattr__ classic show specific code proxy class im hard time imagining would work used proxies really long time tempfile_temporaryfilewrapper aims delegate many operations automatically underlying file object def __getattr__self name attribute lookups delegated underlying file cached nonnumeric results ie methods cached closed friends file self__dict__file getattrfile name issubclasstypea type0 setattrself name return 2x methods need overridden explicitly bound method caching wrong thing __exit__ __enter__ needed list first brought class attention 30 also necessary add def __iter__self return iterselffile wasnt bad case since file doesnt implement many tp_ slots 30 version classes delegate lot operations specific member variable lot verbose cases underlying type delegated implements number container protocols newstyle would needed invoke new method class object defining class class decorator metaclass could provided somewhere make bit tidier hm thinking proxy class sort im thinking mainly classes like _temporaryfilewrapper delegate operations specific member variable expect member variable always specific type note set class attribute corresponding special method eg c__add__ corresponding c slot automatically updated able write class decorator mixin helper function pure python unless completely misunderstand youre yeah typeobject mostly easy way getting complete list special methods tp_ slots without maintain two copies list seems lot cleaner expecting everyone implements proxy object maintain list relevant special methods locates implementation support area code already plenty infrastructure dedicated keeping python visible attributes sync c visible tp_ slots many proxy implementations world need maybe add one stdlib dont know enough different ways people proxy otherwise delegate special methods know feasible provide onesizefitsmost implementation standard library said maybe would enough type instance could queried list special method names implements interpreter access without going __getattribute__ slots class delegating specific type could initialised appropriately something like name delegate_typespecial_methods hasattrcls name def delegationargs kwds self args args 1 arbitrary tuple unpacking getattrselfdelegate nameargs kwds setattrcls name delegation approach suggested original email would instead look like class foo foodelegate_special_methodsdelegate delegate_type delegate_special_methods basically c level implementation loop described except delegation callable could lot efficient given python function another option would provide explicit list documentation slot names tp_ methods interpreter may access without going __getattr__ __getattribute__ discussion bug report got thinking topic commented fact quite magic methods added 2x development cycle think key point missed time fact didnt corresponding tp_ slots __getattr__ __getattribute__ particularly latter intercept fine said documentation approach would probably limiting alternate interpreters though implementations restricted providing optimised access special methods havent done certain cases cpython dont make changes delegation loop shown actually already written follows name dirdelegate_type namestartswith__ nameendswith__ hasattrcls name def delegationargs kwds self args args 1 arbitrary tuple unpacking getattrselfdelegate nameargs kwds setattrcls name delegation thoughts altenative ideas howls protest far bit confusion hopefully makes concerms bit clearer im actually hoping hear people would benefit better support kind delegation interest matter fairly academic based solely tempfile bugs arising initial conversion py3k personal inclination actually put stronger note documentation fact lookup special methods may bypass __getattribute__ entirely leave cheers nick nick coghlan uytankmfgmailcom brisbane australia httpwwwboredomandlazinessorg _______________________________________________ python3000 mailing list smsbmo9552pythonorg httpmailpythonorgmailmanlistinfopython3000 unsubscribe httpmailpythonorgmailmanoptionspython3000python300040tangomucom thu 07 aug 2008 164711 1000 python3000 method populate tp_ slots via getattr