Re: Dictless classes

2012-07-03 Thread Terry Reedy
On 7/3/2012 1:03 AM, Steven D'Aprano wrote: You can create instances without a __dict__ by setting __slots__: Each *instance* does not have its own dict because each would be equal, therefore only one hidden mapping is needed, somewhere. But attribute names must be mapped to objects somehow.

Re: Dictless classes

2012-07-03 Thread Roy Smith
In article , Duncan Booth wrote: > Also you cannot create a subclass of 'type' with non-empty slots (it throws > a type error "nonempty __slots__ not supported for subtype of 'type'"). > However I don't think that's really relevant as even if they did allow you > to use __slots__ it wouldn't

Re: Dictless classes

2012-07-03 Thread Duncan Booth
Steven D'Aprano wrote: > You can create instances without a __dict__ by setting __slots__: That is a necessary but not a sufficient condition. An instance of a class can be created without a dict only if (either you set __slots__ or you implement it in C without a __dict__ attribute) AND none

Re: Dictless classes

2012-07-02 Thread alex23
On Jul 3, 3:03 pm, Steven D'Aprano wrote: > I don't have a use-case for this. But I have some code which assumes that > every class will have a __dict__, and I wonder whether that is a safe > assumption. Remember the recent thread on using a different implementation for .__dict__? https://groups.

Dictless classes

2012-07-02 Thread Steven D'Aprano
You can create instances without a __dict__ by setting __slots__: py> class Dictless: ... __slots__ = ['a', 'b', 'c'] ... py> Dictless().__dict__ Traceback (most recent call last): File "", line 1, in AttributeError: 'Dictless' object has no attribute '__dict__' But the class itself stil