[Python-Dev] Meta-reflections

Martin v. Loewis martin@v.loewis.de
18 Feb 2002 22:31:22 +0100

Kevin Jacobs <jacobs@penguin.theopalgroup.com> writes:

>   1) Should class instances explicitly/directly know all of their attributes?

Since types are classes, this is the same question as "should type
instances know all their attributes?" I don't think they should, in
general: For example, there is no way to find out whether a string
object has an interned pointer, and I don't think there should be.

The __slots__ aren't really different here. In fact, if you do

class Spam(object):
  __slots__ = ('a','b')

s = Spam()
s.a = {}
del Spam.a

you loose access to s.a, even though it is still available (I guess it
is actually a bug that cyclic garbage collection won't find cycles
involving slots).

>   2) Should attribute access follow the same resolution order rules as
>      methods?

Yes, I think so.

>   4) Should __slots__ be flat?

Yes. They should also be a property of the type, not a member of the
dict of the type, and they should be a tuple of member object, not a
list of strings. It might be reasonable to call this property

>        > ('c','d')           # current behavior
>        or
>        > ('a','b','c','d')   # alternate behavior

Neither, nor; assuming you meant Bar to inherit from Foo, it should be

(<member 'a' of 'Foo' objects>, <member 'b' of 'Foo' objects>,
 <member 'c' of 'Bar' objects>, <member 'd' of 'Bar' objects>)