[Python-3000] ABC PEP isinstance issue Was: PEP 31XX: A Type Hierarchy for Numbers (and other algebraic entities) (original) (raw)

Guido van Rossum guido at python.org
Thu Apr 26 02:50:54 CEST 2007


On 4/25/07, Phillip J. Eby <pje at telecommunity.com> wrote:

At 04:43 PM 4/25/2007 -0700, Guido van Rossum wrote: >This is a very good point. Perhaps we can come up with a way to make >isinstance and issubclass into something like GFs (without requiring >the whole GF machinery). > >I'll think about it some more.

special methods are how Python currently defines built-in GFs, so perhaps isinstance and issubclass slots (and their r* counterparts) should suffice.

Yeah. The pragmatic issues are (a) how easy is it to add this to the metaclass; (b) whether to keep the existing "abstract isinstance/issubclass" code which looks for class and bases attributes and believes whatever they return.

OTOH, the old PEP 246 (implemented by both PyProtocols and zope.interface) just uses conform and adapt and basically works the same way as an isinstance/risinstance pair...

Are pairs needed? I was hoping that isinstance(x, C) would only need to be overridden on the class C, and issubclass(D, C) would only need to be overridden on C as well. In particular, the use case brought up here is isinstance(42, Ring) and issubclass(int, Ring). So we'd want to add something to Ring.

-- --Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-3000 mailing list