Why is __root checked for in OrderedDict?

andrew cooke andrew at acooke.org
Thu Apr 7 13:13:28 CEST 2011


If you look at the code in 
http://hg.python.org/cpython/file/6adbf5f3dafb/Lib/collections/__init__.py#l49 the attribute __root is checked for, and only created if missing.  Why?

I ask because, from what I understand, the __init__ method will only be called when the object is first being created, so __root will always be missing.

My only guess is that this allows subclasses to do strange things without breaking the code (and if so, is a nice defensive coding pattern).  But I am worried I am missing something.

Thanks,
Andrew



More information about the Python-list mailing list