gruns/orderedmultidict

What is the intended behavior of iteritems?

Closed this issue · 1 comments

This is in the docstring of iteritems:

Example:
  omd = omdict([(1,1), (1,11), (1,111), (2,2), (3,3)])
  omd.iteritems(1) -> (1,1) -> (1,11) -> (1,111)
  omd.iteritems() -> (1,1) -> (1,11) -> (1,111) -> (2,2) -> (3,3)

However, it doesn't behave as documented:

Python 2.7.4 (default, Apr  6 2013, 19:54:46) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from orderedmultidict import omdict
>>> omd = omdict([(1,1), (1,11), (1,111), (2,2), (3,3)])
>>> list(omd.iteritems(1)) # all ok
[(1, 1), (1, 11), (1, 111)]
>>> list(omd.iteritems()) # not as documented
[(1, 1), (2, 2), (3, 3)]

Then I noticed that the example in the docstring for
iterallitems is virtually identical to the one in iteritems:

Example:
  omd = omdict([(1,1), (1,11), (1,111), (2,2), (3,3)])
  omd.iterallitems() == (1,1) -> (1,11) -> (1,111) -> (2,2) -> (3,3)
  omd.iterallitems(1) == (1,1) -> (1,11) -> (1,111)

So I think either the docstring for iteritems is incorrect OR
the functionality of iteritems is identical to iterallitems?

Awesome -- you found a docstring error.

omd.iteritems() must behave identically to dict.iteritems(). Thus,
the docstring example should be

Example:
  omd = omdict([(1,1), (1,11), (1,111), (2,2), (3,3)])
  omd.iteritems(1) -> (1,1) -> (1,11) -> (1,111)
  omd.iteritems() -> (1,1) -> (2,2) -> (3,3)

I rectified the error and committed the fix. The fix will be included in the
next package version.

Thank you again for bringing this issue to my attention denizdogan.