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

Jim Jewett jimjjewett at gmail.com
Mon Apr 30 04:01:57 CEST 2007


On 4/29/07, Steven Bethard <steven.bethard at gmail.com> wrote:
> On 4/29/07, Talin <talin at acm.org> wrote:
> > If it were technically possible, I would recommend that this PEP have to
> > run the same gauntlet that any other large library addition would, which
> > is to go through a long period of community feedback and criticism,
> > during which a large number of people actually attempt to use the
> > feature for real work.

> This sounds like a pretty good reason to add __isinstance__() and
> __issubclass__().  Then the various ABCs can be distributed as
> third-party modules but can still make sure that things like
> isinstance(42, Real) and issubclass(int, Complex) are True (or
> whatever other assertions people want to make).

Or isexample, so that we aren't locked into implementing ABCs as base classes.

    def isexample(val, ABC):
        return ABC.__example__(val)

    class ABC(object):
        def __example__(cls, val):
            if val in cls.__instance:  return True
            if val in cls.__non_instance:  return False
            for instclass in type(val).__mro__:
                if instclass in __class:  return True
                if instclass in __non_class: return False
            return False

        ... methods to register classes, unregister subclasses, etc

-jJ


More information about the Python-3000 mailing list