This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Somelauw
Recipients Somelauw
Date 2009-01-19.12:41:19
SpamBayes Score 3.8426116e-09
Marked as misclassified No
Message-id <1232368882.79.0.616892747667.issue4998@psf.upfronthosting.co.za>
In-reply-to
Content
>>> f = Fraction()
>>> f.a = 5
>>> f.__slots__
('_numerator', '_denominator')
>>> f.a
5
>>> f.__dict__
{}

When I create my own object, this doesn't happen.

>>> class Slots:
	__slots__ = ("slot1", "slot2")

	
>>> a = Slots()
>>> a.slot3 = 6
Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    a.slot3 = 6
AttributeError: 'Slots' object has no attribute 'slot3'
>>> 

In python2 this only happens when __slots__ is a tuple. (When __slots__ 
is a list, it works correctly)
>>> class Slots:
	__slots__ = ("slot1", "slot2")

	
>>> a = Slots()
>>> a.slot3 = 8
>>> 

Here is a copy-paste from the python3 documentation:
Without a __dict__ variable, instances cannot be assigned new variables 
not listed in the __slots__ definition. Attempts to assign to an 
unlisted variable name raises AttributeError. If dynamic assignment of 
new variables is desired, then add '__dict__' to the sequence of strings 
in the __slots__ declaration.

Any non-string iterable may be assigned to __slots__. Mappings may also 
be used; however, in the future, special meaning may be assigned to the 
values corresponding to each key.
History
Date User Action Args
2009-01-19 12:41:23Somelauwsetrecipients: + Somelauw
2009-01-19 12:41:22Somelauwsetmessageid: <1232368882.79.0.616892747667.issue4998@psf.upfronthosting.co.za>
2009-01-19 12:41:21Somelauwlinkissue4998 messages
2009-01-19 12:41:20Somelauwcreate