Raymond Hettinger <[email protected]> added the comment:
Hmm, I'm looking through the bidict code a bit more. Rather than saying the
dict views are being used in an unsupported way, it is more accurate to say
that your intended meaning for the *mapping* attribute differs from the
published meaning.
Note, the implementation is already skating on thin ice. The values() call
unexpectedly returns an instance of dict_keys(). At first, I was surprised
that this got past the type checker -- you can do set operations with KeysView
but not with a ValuesView.
>>> b.values()
dict_keys([1, 2])
One suggestion is to document *mapping* do exactly what it currently does. The
mappingproxy means that you aren't promising a specific upstream
implementation.
Also consider that bidict could guarantee the meaning of *mapping* and its
underlying store. This would allow users to make fast conversions to other
mapping types:
# This is weird, but useful.
# It might be nice to guarantee it.
>>> OrderedDict(b.values().mapping)
>>> OrderedDict([(1, 'a'), (2, 'b')])
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue45670>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com