[Python-Dev] Replacing self.__dict__ in __init__

Steven D'Aprano steve at pearwood.info
Sat Mar 24 12:09:59 EDT 2018


On Sat, Mar 24, 2018 at 02:18:14PM +0000, Tin Tvrtković wrote:
 
>     self.__dict__ = {'a': a, 'b': b, 'c': c}
> 
> i.e. to replace the instance dictionary altogether. On PyPy, their core
> devs inform me this is a bad idea because the instance dictionary is
> special there, so we won't be doing this on PyPy.
> 
> But is it safe to do on CPython?

I don't know if it's safe, but replacing __init__ is certainly an old 
and famous idiom:

https://code.activestate.com/recipes/66531-singleton-we-dont-need-no-stinkin-singleton-the-bo/


-- 
Steve


More information about the Python-Dev mailing list