Why is __root checked for in OrderedDict?

2011-04-07 Thread andrew cooke
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

Re: Why is __root checked for in OrderedDict?

2011-04-07 Thread Raymond Hettinger
On Apr 7, 4:13 am, andrew cooke and...@acooke.org wrote: If you look at the code inhttp://hg.python.org/cpython/file/6adbf5f3dafb/Lib/collections/__init...the attribute __root is checked for, and only created if missing.  Why? I ask because, from what I understand, the __init__ method will

Re: Why is __root checked for in OrderedDict?

2011-04-07 Thread andrew cooke
Is that normal? I mean, OK, it's possible (and yes I forgot it could be called directly), but is there any usual reason to do so? I guess what I'm asking is: if I'm writing library code should I be this careful? (I've written quite a lot of Python code without this ever biting me, but maybe

Re: Why is __root checked for in OrderedDict?

2011-04-07 Thread Raymond Hettinger
On Apr 7, 2:40 pm, andrew cooke and...@acooke.org wrote: Is that normal?  I mean, OK, it's possible (and yes I forgot it could be called directly), but is there any usual reason to do so? It's common for subclasses to call their parent's __init__ method, so that should emulate dict as nearly