On Fri, Mar 11, 2011 at 10:48 PM, Guido van Rossum <guido at python.org> wrote: >> +1 on making staticmethods callable. I would have found that useful in the >> past. > > IIUC Thomas found that this breaks some current use of staticmethod. >From his first post, I understood the compatibility issue to more be the fact that even if we make it callable, it still needs to return the underlying function from __get__ rather than itself. So making it callable didn't break anything, but changing the behaviour of __get__ did. So long as people follow the policy of applying staticmethod() when stashing things they don't want to turn into methods in class namespaces, that should be fine. The difference between @staticmethod and a "@nondescriptor" decorator that mimics CFunction behaviour would then largely be in whether or not they implemented __get__ at all. >>> hasattr(len, "__get__") False >>> hasattr(staticmethod(len), "__get__") True >>> staticmethod(len).__get__(type) is len True >>> set(dir(len)) - set(dir(staticmethod(len))) {'__call__', '__name__', '__module__', '__self__'} >>> set(dir(staticmethod(len))) - set(dir(len)) {'__func__', '__get__'} Cheers, Nick. -- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4