diff options
author | Andrew M. Kuchling <amk@amk.ca> | 2003-05-20 18:12:21 (GMT) |
---|---|---|
committer | Andrew M. Kuchling <amk@amk.ca> | 2003-05-20 18:12:21 (GMT) |
commit | 28137a09d69fd098b82b3386c92949ad60aebef4 (patch) | |
tree | 8799334a75901dd8111e2e73eaab3b61d1089788 /Doc/whatsnew | |
parent | e960e22579838419541357712bbbc3317c219071 (diff) | |
download | cpython-28137a09d69fd098b82b3386c92949ad60aebef4.zip cpython-28137a09d69fd098b82b3386c92949ad60aebef4.tar.gz cpython-28137a09d69fd098b82b3386c92949ad60aebef4.tar.bz2 |
Don't mention __slots__ as a technique for error avoidance
Diffstat (limited to 'Doc/whatsnew')
-rw-r--r-- | Doc/whatsnew/whatsnew22.tex | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/Doc/whatsnew/whatsnew22.tex b/Doc/whatsnew/whatsnew22.tex index e32e2ab..67e0c81 100644 --- a/Doc/whatsnew/whatsnew22.tex +++ b/Doc/whatsnew/whatsnew22.tex @@ -424,14 +424,9 @@ Finally, it's possible to constrain the list of attributes that can be referenced on an object using the new \member{__slots__} class attribute. Python objects are usually very dynamic; at any time it's possible to define a new attribute on an instance by just doing -\code{obj.new_attr=1}. This is flexible and convenient, but this -flexibility can also lead to bugs, as when you meant to write -\code{obj.template = 'a'} but made a typo and wrote -\code{obj.templtae} by accident. - -A new-style class can define a class attribute named \member{__slots__} -to constrain the list of legal attribute names. An example will make -this clear: +\code{obj.new_attr=1}. A new-style class can define a class attribute named +\member{__slots__} to limit the legal attributes +to a particular set of names. An example will make this clear: \begin{verbatim} >>> class C(object): @@ -443,16 +438,17 @@ None >>> obj.template = 'Test' >>> print obj.template Test ->>> obj.templtae = None +>>> obj.newattr = None Traceback (most recent call last): File "<stdin>", line 1, in ? -AttributeError: 'C' object has no attribute 'templtae' +AttributeError: 'C' object has no attribute 'newattr' \end{verbatim} Note how you get an \exception{AttributeError} on the attempt to assign to an attribute not listed in \member{__slots__}. + \subsection{Related Links} \label{sect-rellinks} |