At 09:16 AM 10/30/03 -0800, Guido van Rossum wrote: >class PickyClassmethod(classmethod): > def __get__(self, obj, cls): > if obj is not None: > raise TypeError, "class method should be called on class only!" > else: > return classmethod.__get__(self, None, cls) > >I don't want to make this behavior the default behavior, because I >can see use cases for calling a class method on an instance too, >knowing that it is a class method; otherwise one would have to write >the ugly x.__class__.foobar(). If there were a 'classonlymethod()' built-in, I'd probably use it, as I use classmethods a fair bit (mostly for specialized constructors), but I don't recall ever desiring to call one via an instance. Do you have an example of the use cases you see? Hm. What if your PickyClassmethod were a built-in called 'constructor' or 'factorymethod'? Probably too confining a name, if there are other uses for class-only methods, I suppose.
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