[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 01:43:45 CEST 2007
- Previous message: [Python-3000] ABC PEP isinstance issue Was: PEP 31XX: A Type Hierarchy for Numbers (and other algebraic entities)
- Next message: [Python-3000] ABC PEP isinstance issue Was: PEP 31XX: A Type Hierarchy for Numbers (and other algebraic entities)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
--Guido
On 4/25/07, Jim Jewett <jimjjewett at gmail.com> wrote:
The current ABC proposal is to use isinstance as the test; Jeffrey Yaskin's numbers PEP highlighted the weakness there with a concrete example.
If you need to an abstraction less powerful than an existing ABC, you're out of luck; you can't just assert that the existing class is already sufficient, nor can you expect everyone else to use multiple annotations. Short of allowing more bases surgery, we need a function parallel to isinstance, which at least makes 3rd-party registration possible. I suspect Phillip will say that we really need to make the ABCs generic functions... but I disagree; I'm not sure that 3rd-party adapters should even be allowed by default, but it should be simple to create an ABC that does take them. Perhaps def isexample(obj, ABC): for cls in obj.class.mro: result = ABC.meets(obj, cls) if result: return result return False class Abstract... # override this with a dictionary to allow 3rd-party registration goodenough = () @classmethod def meets(cls, obj=None, objclass=None): if objclass is cls: # covers isinstance return obj if objclass in cls.goodenough: # Nothing is, by default return cls.goodenough.objclass @classmethod def assertsufficient(cls, objclass, adapter): cls[objclass]=adapter
On 4/25/07, Jeffrey Yasskin <jyasskin at gmail.com> wrote: > If someone needs to split them later, they can use code like:: > import numbers > class IntegralDomain(Ring): ... > numbers.Integral.bases = (IntegralDomain,) + numbers.Integral.bases This only works with old-style classes, which are going away. >>> class Abstract1(object): pass >>> class Abstract2(object): pass >>> Abstract1.bases = (Abstract2,) + Abstract1.bases Traceback (most recent call last): File "<pyshell#33>", line 1, in Abstract1.bases = (Abstract2,) + Abstract1.bases TypeError: bases assignment: 'Abstract2' deallocator differs from 'object'
Python-3000 mailing list Python-3000 at python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/guido%40python.org
-- --Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-3000] ABC PEP isinstance issue Was: PEP 31XX: A Type Hierarchy for Numbers (and other algebraic entities)
- Next message: [Python-3000] ABC PEP isinstance issue Was: PEP 31XX: A Type Hierarchy for Numbers (and other algebraic entities)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]