bidict v0.15.0 Release Notes
Release Date: 2018-03-29 // about 6 years ago-
Speedups and memory usage improvements ++++++++++++++++++++++++++++++++++++++
๐ Use :ref:
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 representativebenchmark <https://github.com/jab/bidict/pull/56#issuecomment-368203591>
__.๐ 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 :ref:
addendum:Bidict Avoids Reference Cycles
documentation.#24 <https://github.com/jab/bidict/issues/20>
__Make :func:
bidict.BidictBase.__eq__
significantly more speed- and memory-efficient when comparing to a non-:class:dict
:class:~collections.abc.Mapping
. (Mapping.__eq__()
\'s inefficient implementation will now never be used.) The implementation is now more reusable as well.Make :func:
bidict.OrderedBidictBase.__iter__
as well as equality comparison slightly faster for ordered bidicts.
๐ Minor Bugfixes ++++++++++++++
:func:
~bidict.namedbidict
now verifies that the providedkeyname
andvalname
are distinct, raising :class:ValueError
if they are equal.:func:
~bidict.namedbidict
now raises :class:TypeError
if the providedbase_type
is not a :class:~bidict.BidirectionalMapping
.If you create a custom bidict subclass whose
_fwdm_cls
differs from its_invm_cls
(as in theFwdKeySortedBidict
example from the :ref:extending:Sorted Bidict Recipes
), the inverse bidirectional mapping type (with_fwdm_cls
and_invm_cls
swapped) is now correctly computed and used automatically for your custom bidict's :attr:~bidict.BidictBase.inverse
bidict.
Miscellaneous +++++++++++++
Classes no longer have to provide an
__inverted__
attribute to be considered virtual subclasses of :class:~bidict.BidirectionalMapping
.If :func:
bidict.inverted
is passed an object with an__inverted__
attribute, it now ensures it is :func:callable
before returning the result of calling it.:func:
~bidict.BidictBase.__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 :class:
~bidict.BidictBase
class from :class:~bidict.frozenbidict
and :class:~bidict.OrderedBidictBase
from :class:~bidict.FrozenOrderedBidict
, 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 :ref:
other-bidict-types:Bidict Types Diagram
and :ref:other-bidict-types: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 :doc:extending
), 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 :attr:
~bidict.RAISE
, :attr:~bidict.OVERWRITE
, and :attr:~bidict.IGNORE
duplication policies are no longer available as attributes of :class:bidict.DuplicationPolicy
, and can now only be accessed as attributes of the :mod:bidict
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()
and :func:bidict.inverted
no longer importable frombidict.util
, and now only importable from the top-level :mod:bidict
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, :attr:
pickle.DEFAULT_PROTOCOL
is 3 anyway, so this will not affect you. However if you are using in Python 2, :attr:~pickle.DEFAULT_PROTOCOL
is 0, so you must now explicitly specify the version in your :func:pickle.dumps
calls, e.g.pickle.dumps(ob, 2)
.