[Python-3000] Abilities / Interfaces

Paul Moore p.f.moore at gmail.com
Thu Nov 23 09:56:22 CET 2006


On 11/23/06, Phillip J. Eby <pje at telecommunity.com> wrote:
> So, the generic function 'as_string' here functions as an "interface" or
> "ability".  Of course, instead of being called 'as_string', it could live
> as an attribute of the 'str' type, e.g. 'str.cast':

OK, I think I just "clicked" with what defop is for. It's to allow you
to define additional behaviour for methods, etc, where the normal def
syntax won't allow something like str.cast? Sorry if that description
is a bit vague - it reflects a feeling of "why bother?"

Is

    defop str.cast(s: MyClass):
        ...

that much better than

    @str.cast.when(MyClass)
    def _(s):
        ...

given that Guido doesn't like "when", so a better name may end up
being used, and the slight namespace pollution of having to come up
with a name to use for the function (I used _ here, maybe there's a
case for allowing def without a name which passes the anonymous
function to the decorator but does no assignment to names...) I could
quite happily live with the decorator form as it stands though - new
syntax seems like overkill.

Paul


More information about the Python-3000 mailing list