A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2003-October/039833.html below:

[Python-Dev] Re: Guido's Magic Code was: inline sort option

[Python-Dev] Re: Guido's Magic Code was: inline sort optionChristian Tanzer tanzer at swing.co.at
Thu Oct 30 12:39:48 EST 2003
> Darn -- it WOULD be better in some cases if one could ONLY call
> a method on the class, NOT on an instance when the call would in
> any case ignore the instance.  Calling dict.fromkeys(L3) is wonderful,
> the problem is that you can also call it on a dict instance, and THAT
> gets confusing.  Similarly, calling list.sorted(iterable) is wonderful,
> but calling it on a list instance that gets ignored, L1.sorted(iterable),
> could perhaps be confusing.

Then why don't you use a custom descriptor which raises an exception
when an instance is passed in? Like:

    def __get__(self, obj, cls):
        if obj is None:
            return new.instancemethod(self.classmeth, cls)
        else:
            raise TypeError, \
              "Calling %s on instance %s ignores instance" % \
              (self.classmeth, obj)

-- 
Christian Tanzer                                    http://www.c-tanzer.at/


More information about the Python-Dev mailing list

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