[Python-3000] PEP 31XX: A Type Hierarchy for Numbers (and other algebraic entities)

Jim Jewett jimjjewett at gmail.com
Wed Apr 25 23:23:25 CEST 2007

On 4/25/07, Jeffrey Yasskin <jyasskin at gmail.com> wrote:
>     class MonoidUnderPlus(Abstract):

Is this useful?  Just because two things are both Monoid instances
doesn't mean I can add them -- they have to be part of the same
Monoid.  By the time you do

    assert isinstance(a, MonoidUnderPlus)
    assert isinstance(b, MonoidUnderPlus)
    assert isinstance(a, b.__class__) or isinstance(b, a.__class__)

I'm not sure how much you've really saved.

> **Open issue:** Do we want to give people a choice of which of the
> following to define, or should we pick one arbitrarily?::

>         def __neg__(self):
>             """Must define this or __sub__()."""
>             return self.zero() - self

>         def __sub__(self, other):
>             """Must define this or __neg__()."""
>             return self + -other

Probably better to pick one;  then it is clear that they have to
override something, and there won't be as many accidental infinite
loops.  If they really want to define the other, they can just do

    def __neg__(self):
        super(_this_class__, self).__neg__()

The decorator doesn't know it isn't a real override.


More information about the Python-3000 mailing list