Guido van Rossum 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. As I understand it, Thomas found that having staticmethod callable AND have staticmethod.__get__ return self breaks code. His exact words were: "With regards to changing staticmethod, in an earlier iteration of the patch I modified staticmethod to be directly callable *and* to return self in its tp_descr_get, and this had a side-effect I hadn't considered: code that used a staticmethod-wrapped object in any way other than calling it, broke." I am suggesting that staticmethod should leave __get__ as is, but add a __call__ method equivalent to this: def __call__(self, *args, **kwargs): func = self.__get__(self) return func(*args, **kwargs) This won't fix the problem with inconsistent behaviour between C and Python callables in classes, but it will reduce the surprising fact that staticmethods aren't callable. Sure, it's easy enough to subclass staticmethod, but the fact that you need to is a gotcha. > This is already illegal (except for classic classes in Python 2). Also > lambda creates a standard function object so it *is* (or *has*?) a > descriptor. So it is. I learn something new. -- Steven
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