"Martin v. Löwis" wrote: >>>> I have a predefined set of members, some of which are optional. >>> Having optional fields is also a good reason. >> >> What is the use of T_OBJECT_EX vs T_OBJECT in PyMemberDef then? > > Right - this works for optional objects. However, it can't possibly > work for any of the other fields.
I have two members, one T_OBJECT and one T_OBJECT_EX. Both are NULL and both still appear in the dir() output. For one, accessing it returns 'None', for the other it raises an exception. I would have expected an element that is not accessible, not even 'None', to also not be visible in dir(). >> I would have thought that the former describes an optional field, >> because the behaviour of accessing it when it is NULL is the same >> as accessing a nonexistent field. However, I see that it still >> appears in the dir() output even if it is NULL, so it seems I'm >> misunderstanding this. > > I suppose that's because there will still be a descriptor for the > field in the class. So is that intentional or is it dir() that could be improved there? Should I file a bugreport? Thanks for the tip with __dict__ in tp_members, that does the job! Uli
-- http://mail.python.org/mailman/listinfo/python-list
