bidict v0.21.0 Release Notes

Release Date: 2020-08-22 // over 1 year ago
    • :mod:bidict now provides type hints <>__! ⌨️ ✅

    Adding type hints to :mod:bidict poses particularly interesting challenges due to the combination of generic types, dynamically-generated types (such as :ref:inverse bidict classes <extending:Dynamic Inverse Class Generation> and :func:namedbidicts <bidict.namedbidict>), 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 (python/typeshed#4435 <>), a :class:typing.Generic bug in Python 3.6 (BPO-41451 <>__), etc.

    That said, this release should provide a solid foundation for code using :mod:bidict that enables static type checking.

    As always, if you spot any opportunities to improve :mod:bidict (including its new type hints), please don't hesitate to submit a PR!

    • ➕ Add :class:bidict.MutableBidirectionalMapping ABC.

    The :ref:other-bidict-types: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 :attr:`object.init_subclass__`.

    • ✂ Remove the no-longer-needed bidict.compat module.

    • 🚚 Move :ref:inverse bidict class access <extending:Dynamic Inverse Class Generation> from a property to an attribute set in :attr:~bidict.BidictBase.__init_subclass__, to save function call overhead on repeated access.

    • :meth:bidict.OrderedBidictBase.__iter__ no longer accepts a reverse keyword argument so that it matches the signature of :meth:container.__iter__.

    • Set the __module__ attribute of various :mod:bidict types (using :func:sys._getframe when necessary) so that private, internal modules are not exposed e.g. in classes' repr strings.

    • :func:~bidict.namedbidict now immediately raises :class:TypeError if the provided base_type does not provide _isinv or :meth:~object.__getstate__, rather than succeeding with a class whose instances may raise :class:AttributeError when these attributes are accessed.