Follow bidict on VersionEye to automatically be notified via email when a new version of bidict is released.
0.13.2.dev0 (not yet released)¶
Support Python 3.6.
(Earlier versions of bidict should work fine on 3.6, but it is officially supported starting in this version.)
BidirectionalMappinghas been refactored into an abstract base class, following the way
collections.abc.Mappingworks. The concrete method implementations it used to provide have been moved into a new
BidirectionalMappingnow also implements
__subclasshook__, so any class that provides a conforming set of attributes (enumerated in
_subclsattrs) will be considered a
OrderedBidirectionalMappinghas been renamed to
OrderedBidictBase, to better reflect its function. (It is not an ABC.)
frozenorderedbidict's hash implementationis now order-sensitive. Since
frozenorderedbidict([(k1, v1), (k2, v2)])does not equal
frozenorderedbidict([(k2, v2), (k1, v1)]), their hashes shouldn’t be equal either. Avoids hash collisions when inserting such objects into the same set or mapping.
frozenorderedbidict._compute_hashfor more documentation of the changes, including the new
frozenorderedbidict._HASH_NITEMS_MAXattributes. If you have an interesting use case that requires overriding these, or suggestions for an alternative implementation, please share your feedback.
This allows creating custom bidict types with extended functionality simply by overriding these attributes in a subclass.
See the new Extending bidict documentation for examples.
Pass any parameters passed to
_fwd.popitemfor greater extensibility.
More concise repr strings for empty bidicts.
bidict.compat.PYPYand remove unused
on_dup_kvkeyword args which allow you to override the default behavior when the key or value of a given item duplicates that (those) of any existing item(s). These can take the following values:
on_dup_kvcan also take
Previously, all of the given items that were processed before the one causing the failure would have been inserted, and no facility was provided to recover which items were inserted and which weren’t, nor to revert any changes made by the failed
update()call. The new behavior makes it easier to reason about and control the effects of failed
putall()method also fails clean.
Internally, this is implemented by storing a log of changes made while an update is being processed, and rolling back the changes when one of them is found to cause an error. This required reimplementing
orderedbidicton top of two dicts and a linked list, rather than two OrderedDicts, since
OrderedDictdoes not expose its underlying linked list.
Add benchmarking to tests.
Drop official support for CPython 3.3. (It may continue to work, but is no longer being tested.)
Breaking API Changes¶
When overwriting the key of an existing value in an
orderedbidict, the position of the existing item is now preserved, overwriting the key of the existing item in place, rather than moving the item to the end. This now matches the behavior of overwriting the value of an existing key, which has always preserved the position of the existing item. (If inserting an item whose key duplicates that of one existing item and whose value duplicates that of another, the existing item whose value is duplicated is still dropped, and the existing item whose key is duplicated still gets its value overwritten in place, as before.)
>>> from bidict import orderedbidict >>> o = orderedbidict([(0, 1), (2, 3)]) >>> o.forceput(4, 1)
previously would have resulted in:
>>> o orderedbidict([(2, 3), (4, 1)])
but now results in:
>>> o orderedbidict([(4, 1), (2, 3)])
- Add Code of Conduct (./CODE_OF_CONDUCT.rst | https://bidict.readthedocs.io/code-of-conduct.html).
- Drop official support for pypy3. (It still may work but is no longer being tested. Support may be added back once pypy3 has made more progress.)
- Minor documentation fixes and improvements.
- Remove several features in favor of keeping the API simpler and the code more maintainable.
- In the interest of protecting data safety more proactively, by default bidict now raises an error on attempting to insert a non-unique value, rather than allowing its associated key to be silently overwritten. See discussion in #21.
forceupdate()method provides a bulk
- Fix bugs in
setdefault()which could leave a bidict in an inconsistent state.
Breaking API Changes¶
bidict.__invert__, and with it, support for the
- Remove support for the slice syntax.
b.invrather than inverting a bidict in place. #20
ValueExistsExceptionwhen attempting to insert a mapping with a non-unique key. #21
loosebidictnow that it suppresses
ValueExistsExceptionrather than the less general
CollapseExceptionhas been subsumed by
KeyExistsExceptionwhen attempting to insert an already-existing key, and
ValueExistsExceptionwhen attempting to insert an already-existing value.
- Fix metadata missing in the 0.9.0rc0 release.
- Add a Changelog! Also a Contributors’ Guide, Gitter chat room, and other community-oriented improvements.
- Adopt Pytest (thanks Tom Viner and Adopt Pytest Month).
- Added property-based tests via hypothesis.
- Other code, tests, and docs improvements.
Breaking API Changes¶
bidict.utilmodule (still available from top-level
bidictmodule as well).
bidict.util.pairs()(also available from top level as
bidict_typekeyword arg to