For backward compatibility, instances of UserDict are not iterable.
This limitation does not exist in Python3.
As a result, six introduces a bug in Python2.
Reproduction steps:
from six.moves import UserDict
d = UserDict({'key': 'output'})
for k in d:
print(d[k])
PY3 output:
output
PY2 output:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/bxsx/.pyenv/versions/2.7.18/lib/python2.7/UserDict.py", line 40, in __getitem__
raise KeyError(key)
KeyError: 0
Solution
This PR addresses it by updating the UserDict attribute to mapUserDict.IterableUserDict on Python 2 and collections.UserDict on Python3.
The PR also adds the moved attribute IterableUserDict which maps to the same attributes as UserDict.
Background
The current implementation of the
UserDict
attribute mapsUserDict.UserDict
tocollections.UserDict
:From the Python 2.7 documentation:
This limitation does not exist in Python3. As a result,
six
introduces a bug in Python2.Reproduction steps:
PY3
output:PY2
output:Solution
This PR addresses it by updating the
UserDict
attribute to mapUserDict.IterableUserDict
on Python 2 andcollections.UserDict
on Python3. The PR also adds the moved attributeIterableUserDict
which maps to the same attributes asUserDict
.The PR fixes #281 issue