[Python-Dev] Replacing self.dict in init (original) (raw)

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


On Sat, Mar 24, 2018 at 02🔞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