55
66<overview >
77<p >The ability to override the class dictionary using a <code >__slots__</code > declaration
8- is supported only by new-style classes. When you add a <code >__slots__</code > declaration to an
9- old-style class it just creates a class attribute called ' __slots__' .</p >
8+ is supported only by new-style classes. When you add a <code >__slots__</code > declaration to an
9+ old-style class it just creates a class attribute called < code > __slots__</ code > .</p >
1010
1111</overview >
1212<recommendation >
1313
14- <p >If you want to override the dictionary for a class, then ensure that the class is a new-style class.
14+ <p >If you want to override the dictionary for a class, then ensure that the class is a new-style class.
1515You can convert an old-style class to a new-style class by inheriting from <code >object</code >.</p >
1616
1717</recommendation >
1818<example >
19- <p >In the following example the <code >KeyedRef </code > class is an old-style class (no inheritance). The
20- <code >__slots__</code > declaration in this class creates a class attribute called ' __slots__' , the class
21- dictionary is unaffected. The <code >KeyedRef2 </code > class is a new-style class so the
22- <code >__slots__</code > declaration causes special compact attributes to be created for each name in
19+ <p >In the following Python 2 example the <code >Point </code > class is an old-style class (no inheritance). The
20+ <code >__slots__</code > declaration in this class creates a class attribute called < code > __slots__</ code > , the class
21+ dictionary is unaffected. The <code >Point2 </code > class is a new-style class so the
22+ <code >__slots__</code > declaration causes special compact attributes to be created for each name in
2323the slots list and saves space by not creating attribute dictionaries.</p >
2424
2525<sample src =" SlotsInOldStyleClass.py" />
@@ -28,7 +28,7 @@ the slots list and saves space by not creating attribute dictionaries.</p>
2828<references >
2929
3030<li >Python Glossary: <a href =" http://docs.python.org/glossary.html#term-new-style-class" >New-style class</a >.</li >
31- <li >Python Language Reference: <a href =" http://docs.python.org/2/reference/datamodel.html#newstyle" >New-style and classic
31+ <li >Python Language Reference: <a href =" http://docs.python.org/2/reference/datamodel.html#newstyle" >New-style and classic
3232classes</a >,
3333 <a href =" http://docs.python.org/reference/datamodel.html#__slots__" >__slots__</a >.</li >
3434
0 commit comments