[Python-3000] ABC PEP isinstance issue Was: PEP 31XX: A Type Hierarchy for Numbers (and other algebraic entities) (original) (raw)
Calvin Spealman ironfroggy at gmail.com
Sat Apr 28 20:27:30 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 ]
On 4/28/07, Guido van Rossum <guido at python.org> wrote:
On 4/28/07, Jean-Paul Calderone <exarkun at divmod.com> wrote: > Aside from the way in which `x' can already lie: > > >>> class X(object): > ... class = property(lambda self: int) > ... > >>> isinstance(X(), int) > True > >>> > > Is this behavior changed/going to be changed in Py3k?
I'm not particularly enamored with it, but I believe it once served a purpose for Zope. Does anyone know if it is still needed? -- --Guido van Rossum (home page: http://www.python.org/~guido/)
Consider this example:
class X(object): pass class Y(object): a = 10 x = X() x.class = Y x.a 10 isinstance(x, Y) True
Now, I'm not saying we must keep this behavior, but it does have its merits. In particular, the cases of type-changing objects, which I'm not convinced always have a place, but thats not the point. The point I want to make is that x is not lying about its type. It IS a Y, because class determines its type. The breakage may not be that x could lie and say its an int, but that it actually can't its a deception of the class, not the type, because you can't assign x.class = int, for example. Either the behavior should work for any type, thus allowing heap types to be assigned to class attributes, changing the type of objects (but, obviously immutables would disallow class assignment). Or, an objects type should not be determined simply by the value of attributes, class, at all.
Does that make sense?
Read my blog! I depend on your acceptance of my opinion! I am interesting! http://ironfroggy-code.blogspot.com/
- 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 ]