Named integers and enums
Hallvard B Furuseth
h.b.furuseth at usit.uio.no
Tue May 25 15:04:06 EDT 2004
Scott David Daniels wrote:
>Hallvard B Furuseth wrote:
>
>> I wonder: isinstance() says that even classic class instances are 'object'
>> instances, even though they do not seem to be (since __slots__ does not
>> work):
>> >>> class o: __slots__ = ()
>> ...
>> >>> isinstance(o(), object)
>> 1
>> >>> o().foo = True
>> >>>
>
> Actually __slots__ works, you just have a funny idea of what __slots__
> is _for_. __slots__ is a _storage_optimization_.
That's not what I mean.
I'm wondering why isinstance() claims that instances of 'o' are
instances of 'object', when 'o' is not declared to be a subclass of
'object'.
I used __slots__ to check if 'o' is a subclass of 'object' anyway, since
__slots__ is documented to only work for new-style classes - i.e.
classes derived from 'object'. Well, it is not. If it had been, the
assignment to o().foo above would have failed.
--
Hallvard
More information about the Python-list
mailing list