Re: __slots__
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: __slots__

From: Aahz <aahz@pythoncraft.com>
Date: Fri Mar 24 2006 - 18:10:12 CET

In article <sFKUf.12114$wD1.3624@trnddc02>,
David Isaac <aisaac0@verizon.net> wrote:
>"Ziga Seilnacht" <ziga.seilnacht@gmail.com> wrote:
>>
>> If you want to restrict attribute asignment, you should use the
>> __setattr__ special method, see:
>> http://docs.python.org/ref/attribute-access.html
>
>That "should" is what I am asking about. If I understand,
>in the simplest case, you want me to say something like
> def __setattr__(self,name,value):
> if name in myattrlist:
> object.__setattr__(self,name,value)
> else:
> raise AttributeError
>instead just saying
> __slots__ = myattrlist
>I understand that this *is* the prevailing advice. But why?

Because __slots__ breaks with inheritance.

-- 
Aahz (aahz@pythoncraft.com)           <*>         http://www.pythoncraft.com/
"Look, it's your affair if you want to play with five people, but don't
go calling it doubles."  --John Cleese anticipates Usenet
Received on Sun Apr 30 21:05:00 2006