bidict v0.12.0 Release Notes

Release Date: 2016-07-03 // about 8 years ago
    • ๐Ÿ†• New/renamed exceptions:

      • :class:~bidict.KeyDuplicationError
      • :class:~bidict.ValueDuplicationError
      • :class:~bidict.KeyAndValueDuplicationError
      • :class:~bidict.DuplicationError (base class for the above)
    • :func:~bidict.bidict.put now accepts on_dup_key, on_dup_val, and on_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:

      • :attr:~bidict.RAISE
      • :attr:~bidict.OVERWRITE
      • :attr:~bidict.IGNORE

    on_dup_kv can also take ON_DUP_VAL.

    If not provided, :func:~bidict.bidict.put uses the :attr:~bidict.RAISE policy by default.

    • ๐Ÿ†• New :func:~bidict.bidict.putall method provides a bulk :func:~bidict.bidict.put API, allowing you to override the default duplication handling policy that :func:~bidict.bidict.update uses.

    • โšก๏ธ :func:~bidict.bidict.update now fails clean, so if an :func:~bidict.bidict.update call raises a :class:~bidict.DuplicationError, 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 :func:~bidict.bidict.update call. The new behavior makes it easier to reason about and control the effects of failed :func:~bidict.bidict.update calls.

    The new :func:~bidict.bidict.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 :class:orderedbidict <bidict.OrderedBidict> on top of two dicts and a linked list, rather than two OrderedDicts, since :class:~collections.OrderedDict does not expose its backing linked list.

    • :func:orderedbidict.move_to_end() <bidict.OrderedBidict.move_to_end> now works on Python < 3.2 as a result of the new :class:orderedbidict <bidict.OrderedBidict> implementation.

    • โž• Add

      • :func:bidict.compat.viewkeys
      • :func:bidict.compat.viewvalues
      • :func:bidict.compat.iterkeys
      • :func:bidict.compat.itervalues
      • bidict.compat.izip
      • bidict.compat.izip_longest

    to complement the existing :func:~bidict.compat.iteritems and :func:~bidict.compat.viewitems compatibility helpers.

    • More efficient implementations of bidict.pairs(), :func:~bidict.inverted, and :func:~bidict.BidictBase.copy.

    • Implement :func:~bidict.BidictBase.__copy__ for use with the :mod:copy module.

    • ๐Ÿ›  Fix issue preventing a client class from inheriting from loosebidict. #34 <https://github.com/jab/bidict/issues/34>__

    • โž• 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 ++++++++++++++++++++

    • ๐Ÿ“‡ Rename KeyExistsException โ†’ :class:~bidict.KeyDuplicationError and ValueExistsException โ†’ :class:~bidict.ValueDuplicationError.

    • When overwriting the key of an existing value in an :class:orderedbidict <bidict.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:

    .. code:: python

     >>> from bidict import orderedbidict  # doctest: +SKIP
     >>> o = orderedbidict([(0, 1), (2, 3)])  # doctest: +SKIP
     >>> o.forceput(4, 1)  # doctest: +SKIP
    

    previously would have resulted in:

    .. code:: python

     >>> o  # doctest: +SKIP
     orderedbidict([(2, 3), (4, 1)])
    

    but now results in:

    .. code:: python

     >>> o  # doctest: +SKIP
     orderedbidict([(4, 1), (2, 3)])