Changelog#
If you or your organization depends on bidict, please consider sponsoring bidict on GitHub.
Tip
Watch bidict releases on GitHub to be notified when new versions of bidict are published. Click the “Watch” dropdown, choose “Custom”, and then choose “Releases”.
0.22.1 (2022-12-31)#
Only include the source code in the source distribution. This reduces the size of the source distribution from ~200kB to ~30kB.
Fix the return type hint of
bidict.inverted()
to return anIterator
, rather than anIterable
.
0.22.0 (2022-03-23)#
Drop support for Python 3.6, which reached end of life on 2021-12-23 and is no longer supported by pip as of pip version 22. Take advantage of this to reduce bidict’s maintenance costs.
Use mypy-appeasing explicit re-exports in
__init__.py
(e.g.import x as x
) so that mypy no longer gives you an implicit re-export error if you run it with--no-implicit-reexport
(or--strict
) against code that imports frombidict
.Update the implementations and type annotations of
bidict.BidictBase.keys()
andbidict.BidictBase.values()
to make use of the newBidictKeysView
type, which works a bit better with type checkers.Inverse bidict instances are now computed lazily the first time the
inverse
attribute is accessed rather than being computed eagerly during initialization. (A bidict’s backing, inverse, one-way mapping is still kept in sync eagerly as any mutations are made, to preserve key- and value-uniqueness.)Optimize initializing a bidict with another bidict. In a microbenchmark on Python 3.10, this now performs over 2x faster.
Optimize updating an empty bidict with another bidict. In a microbenchmark on Python 3.10, this now performs 60-75% faster.
Optimize
copy()
. In a microbenchmark on Python 3.10, this now performs 10-20x faster.Optimize rolling back failed updates to a bidict in the case that the number of items passed to the update call can be determined to be larger than the bidict being updated. Previously this rollback was O(n) in the number of items passed. Now it is O(1), i.e. unboundedly faster.
Optimize
bidict.BidictBase.__contains__()
(the method called when you runkey in mybidict
). In a microbenchmark on Python 3.10, this now performs over 3-10x faster in the False case, and at least 50% faster in the True case.Optimize
bidict.BidictBase.__eq__()
(the method called when you runmybidict == other
). In a microbenchmark on Python 3.10, this now performs 15-25x faster for ordered bidicts, and 7-12x faster for unordered bidicts.Optimize
equals_order_sensitive()
. In a microbenchmark on Python 3.10, this now performs 2x faster for ordered bidicts and 60-90% faster for unordered bidicts.Optimize the
MappingView
objects returned bybidict.OrderedBidict.keys()
,bidict.OrderedBidict.values()
, andbidict.OrderedBidict.items()
to delegate to backingdict_keys
anddict_items
objects if available, which are much faster in CPython. For example, in a microbenchmark on Python 3.10,orderedbi.items() == d.items()
now performs 30-50x faster.Fix a bug where
bidict.BidictBase.__eq__()
was always returning False rather thanNotImplemented
in the case that the argument was not aMapping
, defeating the argument’s own__eq__()
if implemented. As a notable example, bidicts now correctly compare equal tounittest.mock.ANY
.bidict.BidictBase
now adds a__reversed__
implementation to subclasses that don’t have an overridden implementation depending on whether both their backing mappings areReversible
. Previously, a__reversed__
implementation was only added toBidictBase
whenBidictBase._fwdm_cls
wasReversible
. So if aBidictBase
subclass set its_fwdm_cls
to a non-reversible mutable mapping, it would also have to manually set its__reversed__
attribute to None to override the implementation inherited fromBidictBase
. This is no longer necessary thanks to bidict’s newobject.__init_subclass__()
logic.The
MappingView
objects returned bybidict.OrderedBidict.keys()
,bidict.OrderedBidict.values()
, andbidict.OrderedBidict.items()
are nowReversible
. (This was already the case for unordered bidicts when running on Python 3.8+.)Add support for Python 3.9-style dict merge operators (PEP 584).
See the tests for examples.
Update docstrings for
bidict.BidictBase.keys()
,bidict.BidictBase.values()
, andbidict.BidictBase.items()
to include more details.namedbidict()
now exposes the passed-in keyname and valname in the corresponding properties on the generated class.namedbidict()
now requires base_type to be a subclass ofBidictBase
, but no longer requires base_type to provide an_isinv
attribute, whichBidictBase
subclasses no longer provide.When attempting to pickle a bidict’s inverse whose class was dynamically generated, and no reference to the dynamically-generated class has been stored anywhere in
sys.modules
wherepickle
can find it, the pickle call is now more likely to succeed rather than failing with aPicklingError
.Remove the use of slots from (non-ABC) bidict types.
This better matches the mapping implementations in Python’s standard library, and significantly reduces code complexity and maintenance burden. The memory savings conferred by using slots are not noticeable unless you’re creating millions of bidict instances anyway, which is an extremely unusual usage pattern.
Of course, bidicts can still contain millions (or more) items (which is not an unusual usage pattern) without using any more memory than before these changes. Notably, slots are still used in the internal linked list nodes of ordered bidicts to save memory, since as many node instances are created as there are items inserted.
0.21.4 (2021-10-23)#
Explicitly declare support for Python 3.10 as well as some minor internal improvements.
0.21.3 (2021-09-05)#
All bidicts now provide the
equals_order_sensitive()
method, not justOrderedBidict
s.Since support for Python < 3.6 was dropped in v0.21.0,
dict
s provide a deterministic ordering on all supported Python versions, and as a result, all bidicts do too. So now even non-Ordered
bidicts might as well provideequals_order_sensitive()
.See the updated What about order-preserving dicts? docs for more info.
Take better advantage of the fact that dicts became
reversible
in Python 3.8.Specifically, now even non-
Ordered
bidicts provide a__reversed__()
implementation on Python 3.8+ that callsreversed()
on the backing_fwdm
mapping.As a result, if you are using Python 3.8+,
frozenbidict
now gives you everything thatFrozenOrderedBidict
gives you, but with less space overhead.Drop setuptools_scm as a
setup_requires
dependency.Remove the
bidict.__version_info__
attribute.
0.21.2 (2020-09-07)#
0.21.1 (2020-09-07)#
This release was yanked and replaced with the 0.21.2 release, which actually provides the intended changes.
0.21.0 (2020-08-22)#
bidict
now provides type hints! ⌨️ ✅Adding type hints to
bidict
poses particularly interesting challenges due to the combination of generic types, dynamically-generated types (such as inverse bidict classes andnamedbidicts
), and complicating optimizations such as the use of slots and weakrefs.It didn’t take long to hit bugs and missing features in the state of the art for type hinting in Python today, e.g. missing higher-kinded types support (python/typing#548), too-narrow type hints for
collections.abc.Mapping
(python/typeshed#4435), atyping.Generic
bug in Python 3.6 (BPO-41451), etc.That said, this release should provide a solid foundation for code using
bidict
that enables static type checking.As always, if you spot any opportunities to improve
bidict
(including its new type hints), please don’t hesitate to submit a PR!Add
bidict.MutableBidirectionalMapping
ABC.The Bidict Types Diagram has been updated accordingly.
Drop support for Python 3.5, which reaches end of life on 2020-09-13, represents a tiny percentage of bidict downloads on PyPI Stats, and lacks support for variable type hint syntax, ordered dicts, and
object.__init_subclass__
.Remove the no-longer-needed
bidict.compat
module.Move inverse bidict class access from a property to an attribute set in
__init_subclass__
, to save function call overhead on repeated access.bidict.OrderedBidictBase.__iter__()
no longer accepts areverse
keyword argument so that it matches the signature ofcontainer.__iter__()
.Set the
__module__
attribute of variousbidict
types (usingsys._getframe()
when necessary) so that private, internal modules are not exposed e.g. in classes’ repr strings.namedbidict()
now immediately raisesTypeError
if the providedbase_type
does not provide_isinv
or__getstate__()
, rather than succeeding with a class whose instances may raiseAttributeError
when these attributes are accessed.
0.20.0 (2020-07-23)#
The following breaking changes are expected to affect few if any users.
Remove APIs deprecated in the previous release:
bidict.OVERWRITE
andbidict.IGNORE
.The
on_dup_key
,on_dup_val
, andon_dup_kv
arguments ofput()
andputall()
.The
on_dup_key
,on_dup_val
, andon_dup_kv
bidict
class attributes.Remove
bidict.BidirectionalMapping.__subclasshook__()
due to lack of use and maintenance cost.Fixes a bug introduced in 0.15.0 that caused any class with an
inverse
attribute to be incorrectly considered a subclass ofcollections.abc.Mapping
. #111
0.19.0 (2020-01-09)#
Drop support for Python 2 as promised in v0.18.2.
The
bidict.compat
module has been pruned accordingly.This makes bidict more efficient on Python 3 and enables further improvement to bidict in the future.
Deprecate
bidict.OVERWRITE
andbidict.IGNORE
. AUserWarning
will now be emitted if these are used.bidict.DROP_OLD
andbidict.DROP_NEW
should be used instead.Rename
DuplicationPolicy
toOnDupAction
(and implement it via anEnum
).An
OnDupAction
may be one ofRAISE
,DROP_OLD
, orDROP_NEW
.Expose the new
OnDup
class to contain the threeOnDupAction
s that should be taken upon encountering the three kinds of duplication that can occur (key, val, kv).Provide the
ON_DUP_DEFAULT
,ON_DUP_RAISE
, andON_DUP_DROP_OLD
OnDup
convenience instances.Deprecate the
on_dup_key
,on_dup_val
, andon_dup_kv
arguments ofput()
andputall()
. AUserWarning
will now be emitted if these are used.These have been subsumed by the new on_dup argument, which takes an
OnDup
instance.Use it like this:
bi.put(1, 2, OnDup(key=RAISE, val=...))
. Or pass one of the instances already provided, such asON_DUP_DROP_OLD
. Or just don’t pass an on_dup argument to use the default value ofON_DUP_RAISE
.The Values Must Be Unique docs have been updated accordingly.
Deprecate the
on_dup_key
,on_dup_val
, andon_dup_kv
bidict
class attributes. AUserWarning
will now be emitted if these are used.These have been subsumed by the new
on_dup
class attribute, which takes anOnDup
instance.See the updated Extending bidict docs for example usage.
Improve the more efficient implementations of
keys()
,values()
, anditems()
, and now also provide a more efficient implementation of__iter__()
by delegating to backingdict
s in the bidict types for which this is possible.Move
bidict.BidictBase.values()
tobidict.BidirectionalMapping.values()
, since the implementation is generic.No longer use
__all__
inbidict
’s__init__.py
.
0.18.4 (2020-11-02)#
Backport fix from v0.20.0 that removes
bidict.BidirectionalMapping.__subclasshook__()
due to lack of use and maintenance cost.
0.18.3 (2019-09-22)#
Improve validation of names passed to
namedbidict()
: Usestr.isidentifier()
on Python 3, and a better regex on Python 2.On Python 3, set
__qualname__
onnamedbidict()
classes based on the providedtypename
argument.
0.18.2 (2019-09-08)#
Warn that Python 2 support will be dropped in a future release when Python 2 is detected.
0.18.1 (2019-09-03)#
Fix a regression introduced by the memory optimizations added in 0.15.0 which caused
deepcopied
andunpickled
bidicts to have their inverses set incorrectly. #94
0.18.0 (2019-02-14)#
Rename
bidict.BidirectionalMapping.inv
toinverse
and makebidict.BidictBase.inv
an alias forinverse
. #86bidict.BidirectionalMapping.__subclasshook__()
now requires aninverse
attribute rather than aninv
attribute for a class to qualify as a virtual subclass. This breaking change is expected to affect few if any users.Add Python 2/3-compatible
bidict.compat.collections_abc
alias.Stop testing Python 3.4 on CI, and warn when Python 3 < 3.5 is detected rather than Python 3 < 3.3.
Python 3.4 reaches end of life on 2019-03-18. As of January 2019, 3.4 represents only about 3% of bidict downloads on PyPI Stats.
0.17.5 (2018-11-19)#
Improvements to performance and delegation logic, with minor breaking changes to semi-private APIs.
Remove the
__delegate__
instance attribute added in the previous release. It was overly general and not worth the cost.Instead of checking
self.__delegate__
and delegating accordingly each time a possibly-delegating method is called, revert back to using “delegated-to-fwdm” mixin classes (now found inbidict._delegating_mixins
), and resurrect a mutable bidict parent class that omits the mixins asbidict.MutableBidict
.Rename
__repr_delegate__
to_repr_delegate
.
0.17.4 (2018-11-14)#
Minor code, interop, and (semi-)private API improvements.
OrderedBidict
optimizations and code improvements.Use
bidict
s for the backing_fwdm
and_invm
mappings, obviating the need to store key and value data in linked list nodes.Refactor proxied- (i.e. delegated-) to-
_fwdm
logic for better composability and interoperability.Drop the
_Proxied*
mixin classes and instead move their methods intoBidictBase
, which now checks for an object defined by theBidictBase.__delegate__
attribute. TheBidictBase.__delegate__
object will be delegated to if the method is available on it, otherwise a default implementation (e.g. inherited fromMapping
) will be used otherwise. Subclasses may set__delegate__ = None
to opt out.Consolidate
_MutableBidict
intobidict.bidict
now that the dropped mixin classes make it unnecessary.Change
__repr_delegate__
to simply take a type likedict
orlist
.Upgrade to latest major sortedcontainers version (from v1 to v2) for the SortedBidict Recipes.
bidict.compat.{view,iter}{keys,values,items}
on Python 2 no longer assumes the target object implements these methods, as they’re not actually part of theMapping
interface, and provides fallback implementations when the methods are unavailable. This allows the SortedBidict Recipes to continue to work with sortedcontainers v2 on Python 2.
0.17.3 (2018-09-18)#
Improve packaging by adding a pyproject.toml and by including more supporting files in the distribution. #81
Drop pytest-runner and support for running tests via
python setup.py test
in preference topytest
orpython -m pytest
.
0.17.2 (2018-04-30)#
Memory usage improvements
Use less memory in the linked lists that back
OrderedBidict
s by storing node data unpacked rather than in (key, value) tuple objects.
0.17.1 (2018-04-28)#
Bugfix Release
Fix a regression in 0.17.0 that could cause erroneous behavior
when updating items of an Orderedbidict
’s inverse,
e.g. some_ordered_bidict.inv[foo] = bar
.
0.17.0 (2018-04-25)#
Speedups and memory usage improvements
Pass
keys()
,values()
, anditems()
calls (as well as theiriter*
andview*
counterparts on Python 2) through to the backing_fwdm
and_invm
dicts so that they run as fast as possible (i.e. at C speed on CPython), rather than using the slower implementations inherited fromcollections.abc.Mapping
.Use weakrefs in the linked lists that back
OrderedBidict
s to avoid creating strong reference cycles.Memory for an ordered bidict that you create can now be reclaimed in CPython as soon as you no longer hold any references to it, rather than having to wait until the next garbage collection. #71
Misc
Add
bidict.__version_info__
attribute to complementbidict.__version__
.
0.16.0 (2018-04-06)#
Minor code and efficiency improvements to
inverted()
and
bidict._iter._iteritems_args_kw
(formerly bidict.pairs()
).
Minor Breaking API Changes
The following breaking changes are expected to affect few if any users.
Rename
bidict.pairs()
→bidict._iter._iteritems_args_kw
.
0.15.0 (2018-03-29)#
Speedups and memory usage improvements
Use __slots__ to speed up bidict attribute access and reduce memory usage. On Python 3, instantiating a large number of bidicts now uses ~57% the amount of memory that it used before, and on Python 2 only ~33% the amount of memory that it used before, in a simple but representative benchmark.
Use weakrefs to refer to a bidict’s inverse internally, no longer creating a strong reference cycle. Memory for a bidict that you create can now be reclaimed in CPython as soon as you no longer hold any references to it, rather than having to wait for the next garbage collection. See the new bidict Avoids Reference Cycles documentation. #24
Make
bidict.BidictBase.__eq__()
significantly more speed- and memory-efficient when comparing to a non-dict
Mapping
. (Mapping.__eq__()
's inefficient implementation will now never be used.) The implementation is now more reusable as well.Make
bidict.OrderedBidictBase.__iter__()
as well as equality comparison slightly faster for ordered bidicts.
Minor Bugfixes
namedbidict()
now verifies that the providedkeyname
andvalname
are distinct, raisingValueError
if they are equal.namedbidict()
now raisesTypeError
if the providedbase_type
is not aBidirectionalMapping
.If you create a custom bidict subclass whose
_fwdm_cls
differs from its_invm_cls
(as in theFwdKeySortedBidict
example from the SortedBidict Recipes), the inverse bidirectional mapping type (with_fwdm_cls
and_invm_cls
swapped) is now correctly computed and used automatically for your custom bidict’sinverse
bidict.
Misc
Classes no longer have to provide an
__inverted__
attribute to be considered virtual subclasses ofBidirectionalMapping
.If
bidict.inverted()
is passed an object with an__inverted__
attribute, it now ensures it iscallable()
before returning the result of calling it.__repr__()
no longer checks for a__reversed__
method to determine whether to use an ordered or unordered-style repr. It now calls the new__repr_delegate__
instead (which may be overridden if needed), for better composability.
Minor Breaking API Changes
The following breaking changes are expected to affect few if any users.
Split back out the
BidictBase
class fromfrozenbidict
andOrderedBidictBase
fromFrozenOrderedBidict
, reverting the merging of these in 0.14.0. Having e.g.issubclass(bidict, frozenbidict) == True
was confusing, so this change restoresissubclass(bidict, frozenbidict) == False
.See the updated Bidict Types Diagram and Polymorphism documentation.
Rename:
bidict.BidictBase.fwdm
→._fwdm
bidict.BidictBase.invm
→._invm
bidict.BidictBase.fwd_cls
→._fwdm_cls
bidict.BidictBase.inv_cls
→._invm_cls
bidict.BidictBase.isinv
→._isinv
Though overriding
_fwdm_cls
and_invm_cls
remains supported (see Extending bidict), this is not a common enough use case to warrant public names. Most users do not need to know or care about any of these.The
RAISE
,OVERWRITE
, andIGNORE
duplication policies are no longer available as attributes ofDuplicationPolicy
, and can now only be accessed as attributes of thebidict
module namespace, which was the canonical way to refer to them anyway. It is now no longer possible to create an infinite chain likeDuplicationPolicy.RAISE.RAISE.RAISE...
Make
bidict.pairs()
andbidict.inverted()
no longer importable frombidict.util
, and now only importable from the top-levelbidict
module. (bidict.util
was renamedbidict._util
.)Pickling ordered bidicts now requires at least version 2 of the pickle protocol. If you are using Python 3,
pickle.DEFAULT_PROTOCOL
is 3 anyway, so this will not affect you. However if you are using in Python 2,DEFAULT_PROTOCOL
is 0, so you must now explicitly specify the version in yourpickle.dumps()
calls, e.g.pickle.dumps(ob, 2)
.
0.14.2 (2017-12-06)#
Make initializing (or updating an empty bidict) from only another
BidirectionalMapping
more efficient by skipping unnecessary duplication checking.Fix accidental ignoring of specified
base_type
argument when (un)pickling anamedbidict()
.Fix incorrect inversion of
some_named_bidict.inv.<fwdname>_for
andsome_named_bidict.inv.<invname>_for
.Only warn when an unsupported Python version is detected (e.g. Python < 2.7) rather than raising
AssertionError
.
0.14.1 (2017-11-28)#
Fix a bug introduced in 0.14.0 where hashing a
frozenbidict
’s inverse (e.g.f = frozenbidict(); {f.inv: '...'}
) would cause anAttributeError
.Fix a bug introduced in 0.14.0 for Python 2 users where attempting to call
viewitems()
would cause aTypeError
. #48
0.14.0 (2017-11-20)#
Fix a bug where
bidict
’s default on_dup_kv policy was set toRAISE
, rather than matching whatever on_dup_val policy was in effect as was documented.Fix a bug that could happen when using Python’s optimization (
-O
) flag that could leave an ordered bidict in an inconsistent state when dealing with duplicated, overwritten keys or values. If you do not use optimizations (specifically, skippingassert
statements), this would not have affected you.Fix a bug introduced by the optimizations in 0.13.0 that could cause a frozen bidict that compared equal to another mapping to have a different hash value from the other mapping, violating Python’s object model. This would only have affected you if you were inserting a frozen bidict and some other immutable mapping that it compared equal to into the same set or mapping.
Reduce the memory usage of ordered bidicts.
Make copying of ordered bidicts faster.
Improvements to tests and CI, including:
Test on Windows
Test with PyPy3
Test with CPython 3.7-dev
Test with optimization flags
Require pylint to pass
Breaking API Changes
This release includes multiple API simplifications and improvements.
Rename:
orderedbidict
→OrderedBidict
frozenorderedbidict
→FrozenOrderedBidict
so that these now match the case of
collections.OrderedDict
.The names of the
bidict
,namedbidict()
, andfrozenbidict
classes have been retained as all-lowercase so that they continue to match the case ofdict
,namedtuple()
, andfrozenset
, respectively.The
ON_DUP_VAL
duplication policy value for on_dup_kv has been removed. UseNone
instead.Merge
frozenbidict
andBidictBase
together and removeBidictBase
.frozenbidict
is now the concrete base class that all other bidict types derive from. See the updated Bidict Types Diagram.Merge
frozenbidict
andFrozenBidictBase
together and removeFrozenBidictBase
. See the updated Bidict Types Diagram.Merge
frozenorderedbidict
andOrderedBidictBase
together into a singleFrozenOrderedBidict
class and removeOrderedBidictBase
.OrderedBidict
now extendsFrozenOrderedBidict
to add mutable behavior. See the updated Bidict Types Diagram.Make
__eq__()
always perform an order-insensitive equality test, even if the other mapping is ordered.Previously,
__eq__()
was only order-sensitive for otherOrderedBidictBase
subclasses, and order-insensitive otherwise.Use the new
equals_order_sensitive()
method for order-sensitive equality comparison.orderedbidict._should_compare_order_sensitive()
has been removed.frozenorderedbidict._HASH_NITEMS_MAX
has been removed. Since its hash value must be computed from all contained items (so that hash results are consistent with equality comparisons against unordered mappings), the number of items that influence the hash value should not be limitable.frozenbidict._USE_ITEMSVIEW_HASH
has been removed, andfrozenbidict.compute_hash()
now usescollections.ItemsView._hash()
to compute the hash always, not just when running on PyPy.Override
frozenbidict.compute_hash()
to returnhash(frozenset(iteritems(self)))
if you prefer the old default behavior on CPython, which takes linear rather than constant space, but which uses thefrozenset_hash
routine (implemented insetobject.c
) rather than the pure PythonItemsView._hash()
routine.loosebidict
andlooseorderedbidict
have been removed. A simple recipe to implement equivalents yourself is now given in Extending bidict.Rename
FrozenBidictBase._compute_hash()
→frozenbidict.compute_hash()
.Rename
DuplicationBehavior
→DuplicationPolicy
.Rename:
BidictBase._fwd_class
→.fwd_cls
BidictBase._inv_class
→.inv_cls
BidictBase._on_dup_key
→on_dup_key
BidictBase._on_dup_val
→on_dup_val
BidictBase._on_dup_kv
→on_dup_kv
0.13.1 (2017-03-15)#
Fix regression introduced by the new
__subclasshook__()
functionality in 0.13.0 so thatissubclass(OldStyleClass, BidirectionalMapping)
once again works with old-style classes, returningFalse
rather than raisingAttributeError
#41
0.13.0 (2017-01-19)#
Support Python 3.6.
(Earlier versions of bidict should work fine on 3.6, but it is officially supported starting in this version.)
BidirectionalMapping
has been refactored into an abstract base class, following the waycollections.abc.Mapping
works. The concrete method implementations it used to provide have been moved into a newBidictBase
subclass.BidirectionalMapping
now also implements__subclasshook__()
, so any class that provides a conforming set of attributes (enumerated in_subclsattrs
) will be considered aBidirectionalMapping
subclass automatically.OrderedBidirectionalMapping
has been renamed toOrderedBidictBase
, to better reflect its function. (It is not an ABC.)A new
FrozenBidictBase
class has been factored out offrozenbidict
andfrozenorderedbidict
. This implements common behavior such as caching the result of__hash__
after the first call.The hash implementations of
frozenbidict
andfrozenorderedbidict
. have been reworked to improve performance and flexibility.frozenorderedbidict
’s hash implementation is now order-sensitive.See
frozenbidict._compute_hash()
andfrozenorderedbidict._compute_hash
for more documentation of the changes, including the newfrozenbidict._USE_ITEMSVIEW_HASH
andfrozenorderedbidict._HASH_NITEMS_MAX
attributes. If you have an interesting use case that requires overriding these, or suggestions for an alternative implementation, please share your feedback.Add
_fwd_class
and_inv_class
attributes representing the backingMapping
types used internally to store the forward and inverse dictionaries, respectively.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
popitem()
through to_fwd.popitem
for greater extensibility.More concise repr strings for empty bidicts.
e.g.
bidict()
rather thanbidict({})
andorderedbidict()
rather thanorderedbidict([])
.Add
bidict.compat.PYPY
and remove unusedbidict.compat.izip_longest
.
0.12.0 (2016-07-03)#
New/renamed exceptions:
DuplicationError
(base class for the above)
put()
now acceptson_dup_key
,on_dup_val
, andon_dup_kv
keyword args which allow you to override the default policy when the key or value of a given item duplicates any existing item’s. These can take the following values:OVERWRITE
IGNORE
on_dup_kv
can also takeON_DUP_VAL
.New
putall()
method provides a bulkput()
API, allowing you to override the default duplication handling policy thatupdate()
uses.update()
now fails clean, so if anupdate()
call raises aDuplicationError
, you can now be sure that none of the given items was inserted.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 failedupdate()
calls.The new
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
orderedbidict
on top of two dicts and a linked list, rather than two OrderedDicts, sinceOrderedDict
does not expose its backing linked list.orderedbidict.move_to_end()
now works on Python < 3.2 as a result of the neworderedbidict
implementation.Add
bidict.compat.viewkeys
bidict.compat.viewvalues
bidict.compat.iterkeys
bidict.compat.itervalues
bidict.compat.izip
bidict.compat.izip_longest
to complement the existing
bidict.compat.iteritems
andbidict.compat.viewitems
compatibility helpers.More efficient implementations of
bidict.pairs()
,inverted()
, andcopy()
.Implement
__copy__()
for use with thecopy
module.Fix issue preventing a client class from inheriting from
loosebidict
. #34Add benchmarking to tests.
Drop official support for CPython 3.3. (It may continue to work, but is no longer being tested.)
Breaking API Changes
Rename
KeyExistsException
→KeyDuplicationError
andValueExistsException
→ValueDuplicationError
.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.)For example:
o = orderedbidict([(0, 1), (2, 3)]) o.forceput(4, 1)
previously would have resulted in:
orderedbidict([(2, 3), (4, 1)])
but now results in:
orderedbidict([(4, 1), (2, 3)])
0.11.0 (2016-02-05)#
Add
orderedbidict
,looseorderedbidict
, andfrozenorderedbidict
.Add Code of Conduct.
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.)
0.10.0.post1 (2015-12-23)#
Minor documentation fixes and improvements.
0.10.0 (2015-12-23)#
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.
New
forceupdate()
method provides a bulkforceput()
operation.Fix bugs in
pop
andsetdefault
which could leave a bidict in an inconsistent state.
Breaking API Changes
Remove
bidict.__invert__
, and with it, support for the~b
syntax. Useinv
instead. #19Remove support for the slice syntax. Use
b.inv[val]
rather thanb[:val]
. #19Remove
bidict.invert
. Useinv
rather than inverting a bidict in place. #20Raise
ValueExistsException
when attempting to insert a mapping with a non-unique key. #21Rename
collapsingbidict
→loosebidict
now that it suppressesValueExistsException
rather than the less generalCollapseException
. #21CollapseException
has been subsumed byValueExistsException
. #21put()
now raisesKeyExistsException
when attempting to insert an already-existing key, andValueExistsException
when attempting to insert an already-existing value.
0.9.0.post1 (2015-06-06)#
Fix metadata missing in the 0.9.0rc0 release.
0.9.0rc0 (2015-05-30)#
Add this changelog, Contributors’ Guide, Gitter chat room, and other community-oriented improvements.
Adopt Pytest.
Add property-based tests via hypothesis.
Other code, tests, and docs improvements.
Breaking API Changes
Move
bidict.iteritems()
andbidict.viewitems()
to newbidict.compat
module.Move
bidict.inverted
to newbidict.util
module (still available from top-levelbidict
module as well).Move
bidict.fancy_iteritems()
→bidict.util.pairs()
(also available from top level asbidict.pairs()
).Rename
bidict.namedbidict()
'sbidict_type
argument →base_type
.