[Python-Dev] Callable, non-descriptor class attributes. (original) (raw)
Nick Coghlan ncoghlan at gmail.com
Sat Mar 12 06:44:41 CET 2011
- Previous message: [Python-Dev] Callable, non-descriptor class attributes.
- Next message: [Python-Dev] Callable, non-descriptor class attributes.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message: [Python-Dev] Callable, non-descriptor class attributes.
- Next message: [Python-Dev] Callable, non-descriptor class attributes.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]