[Python-3000] Special methods and interface-based type system

Bill Janssen janssen at parc.com
Wed Nov 22 19:55:28 CET 2006


Talking about the Abilities/Interfaces made me think about some of our
"rogue" special method names.  In the Language Reference, it says, "A
class can implement certain operations that are invoked by special
syntax (such as arithmetic operations or subscripting and slicing) by
defining methods with special names."  But there are all these methods
with special names like __len__ or __unicode__ which seem to be
provided for the benefit of built-in functions, rather than for
support of syntax.  Presumably in an interface-based Python, these
methods would turn into regularly-named methods on an ABC, so that
__len__ would become

  class container:
    ...
    def len(self):
      raise NotImplemented

Though, thinking about it some more, I don't see why *all* syntactic
operations wouldn't just invoke the appropriate normally-named method
on a specific ABC.  "<", for instance, would presumably invoke
"object.lessthan" (or perhaps "comparable.lessthan").  So another
benefit would be the ability to wean Python away from this
mangled-name oddness, which seems to me an HCI improvement.

Bill


More information about the Python-3000 mailing list