Debian Codegraph @

CHANGELOG.rst

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 .. Forward declarations for all the custom interpreted text roles that
2 Sphinx defines and that are used below. This helps Sphinx-unaware tools
3 (e.g. rst2html, PyPI's and GitHub's renderers, etc.).
4 .. role:: doc
5 .. role:: ref
6
7
8 Changelog
9 =========
10
11 .. image:: https://img.shields.io/badge/GitHub-sponsor-ff69b4
12 :target: https://github.com/sponsors/jab
13 :alt: Sponsor
14
15
16 :sup:`If you or your organization depends on bidict,
17 please consider sponsoring bidict on GitHub.`
18
19
20 .. tip::
21 Watch `bidict releases on GitHub <https://github.com/jab/bidict/releases>`__
22 to be notified when new versions of bidict are published.
23 Click the "Watch" dropdown, choose "Custom", and then choose "Releases".
24
25
26 0.24.1 (2026-08-25)
27 -------------------
28
29 - Fix the ``RECORD`` file in the published 0.24.0 wheel
30 by upgrading to a fixed version of ``uv_build``.
31 :issue:`406`
32
33 - Fix a test failure on Python 3.15
34 caused by changes to :class:`~collections.UserDict`.
35 :issue:`407`
36
37
38 0.24.0 (2026-08-24)
39 -------------------
40
41 - Remove ``bidict.metadata`` and associated metadata from the
42 :mod:`bidict` module (e.g. ``bidict.__version__``).
43 Use e.g. :func:`importlib.metadata.metadata("bidict")["Version"]
44 <importlib.metadata.metadata>` instead.
45
46 - Fix a bug where pickling or :func:`~copy.deepcopy`\ing an instance of a
47 dynamically-generated inverse class
48 (see :ref:`extending:Dynamic Inverse Class Generation`)
49 could change the order of its items.
50 :issue:`398`
51
52 Pickles written by bidict 0.23.1 and earlier can no longer be read.
53 They call the private ``BidictBase._from_other()``
54 with an argument it no longer accepts,
55 which was retained for no other purpose.
56 Pickle compatibility across versions
57 `has never been guaranteed
58 <https://docs.python.org/3/library/pickle.html#comparison-with-json>`__,
59 and dropping it here keeps
60 :meth:`~bidict.BidictBase.__reduce__` free of special cases.
61
62 - Fix a bug where a non-ordered bidict's
63 :meth:`~bidict.BidictBase.values` view
64 could yield its values in a different order than
65 :meth:`~bidict.BidictBase.keys` yields the corresponding keys,
66 so that e.g. ``zip(b.keys(), b.values())``
67 silently paired up the wrong keys and values.
68
69 - Fix a bug where :meth:`~bidict.MutableBidict.putall`
70 and :meth:`~bidict.MutableBidict.update`
71 could leave earlier items inserted when a later item in a bulk update
72 raised a non-duplication exception,
73 rather than failing clean.
74 :issue:`389`
75
76 - Fix a bug where a bulk update did not fail clean at all
77 when the :class:`~bidict.OnDup` in effect contained no
78 :attr:`~bidict.RAISE` action –
79 as with :meth:`~bidict.MutableBidict.forceupdate`,
80 :meth:`~bidict.MutableBidict.putall` passed :attr:`~bidict.ON_DUP_DROP_OLD`,
81 or :meth:`~bidict.MutableBidict.update` on a subclass
82 that overrides :attr:`~bidict.BidictBase.on_dup`
83 (e.g. the ``YoloBidict`` recipe in :doc:`extending`).
84 Rollback was previously enabled only when a duplication error was possible,
85 but a bulk update can also fail while unpacking an item,
86 hashing a key or value, or writing to a backing mapping.
87 Rollback is now always enabled for these methods.
88 :issue:`392`
89
90 - Fix a bug where a write or removal that a custom backing mapping refused
91 could leave a custom bidict's two backing mappings out of sync,
92 breaking the bidirectional invariant,
93 rather than failing clean.
94 :issue:`401`
95 :issue:`403`
96
97 - Fix a bug where mutating an :class:`~bidict.OrderedBidict`
98 while iterating over it produced incorrect behavior
99 rather than raising an error.
100 :issue:`393`
101
102 - A bidict and its inverse now always refer to the same object
103 for each contained key and value,
104 rather than possibly to equivalent but distinct ones,
105 so that e.g. ``b.inverse[b[key]] is key`` always holds.
106 Writing an item whose key or value is equal to a contained one
107 now keeps the object already contained,
108 as :class:`dict` does when a key is overwritten,
109 instead of keeping one object in each direction.
110 *See also* :ref:`addendum:Equivalent but distinct \:class\:\`~collections.abc.Hashable\`\\s`
111 :issue:`396`
112
113 - Fix a bug where setting an already-contained (key, value) pair
114 spuriously raised :class:`~bidict.KeyAndValueDuplicationError`
115 or ``AssertionError`` (rather than being a no-op, as documented)
116 when the key or value has non-reflexive equality (e.g. *nan*)
117 or asymmetric equality.
118 :issue:`377`
119
120 - Fix a bug where set operations between an :class:`~bidict.OrderedBidict`'s
121 keys view and its items view (or vice versa) raised :class:`TypeError`
122 (or, for ``==``, returned the wrong result)
123 rather than behaving like the equivalent plain :class:`dict` views.
124 :issue:`376`
125
126 - Single-item writes such as
127 :meth:`~bidict.MutableBidict.__setitem__`,
128 :meth:`~bidict.MutableBidict.put`, and
129 :meth:`~bidict.MutableBidict.forceput`
130 are now ~6x faster:
131 most of what they cost was never the write itself,
132 but typing machinery being re-evaluated on every call.
133 Iterating an :class:`~bidict.OrderedBidict` is also ~1.2x faster.
134 Everything else is within a couple of percent of 0.23.1.
135
136 - A bidict backed by a :class:`dict` *subclass*
137 now gets that mapping's own views from
138 :meth:`~bidict.BidictBase.keys` and :meth:`~bidict.BidictBase.items`,
139 as a bidict backed by an exact :class:`dict` already did.
140 Previously only an exact :class:`dict` qualified,
141 so such a bidict got generic views instead,
142 which were not :class:`~collections.abc.Reversible`
143 (even when the bidict itself was),
144 had no ``.mapping`` attribute,
145 and performed their set operations in Python rather than in C.
146 This affects every backing mapping used in the recipes in :doc:`extending`,
147 since :class:`collections.OrderedDict`,
148 :class:`collections.defaultdict`,
149 and ``sortedcontainers.SortedDict``
150 are all :class:`dict` subclasses.
151
152 - Fix a bug where a subclass of a bidict class
153 whose backing mappings are not :class:`~collections.abc.Reversible`
154 could not itself be reversible,
155 even when it specified backing mappings that are.
156
157 - Fix a bug where an :class:`~bidict.OrderedBidictBase` that is not an
158 :class:`~bidict.OrderedBidict`
159 could yield its items in the wrong order from
160 :meth:`~bidict.OrderedBidictBase.keys`,
161 :meth:`~bidict.OrderedBidictBase.items`,
162 :meth:`~bidict.BidictBase.values`,
163 :func:`repr`, and
164 :meth:`~bidict.BidictBase.equals_order_sensitive`.
165
166
167 0.23.1 (2024-02-18)
168 -------------------
169
170 Fix a regression in 0.23.0 that could defeat type inference
171 of a bidict's key type and value type when running in Python 3.8 or 3.9.
172 :issue:`310`
173
174
175 0.23.0 (2024-02-14)
176 -------------------
177
178 Primarily, this release simplifies bidict by removing minor features
179 that are no longer necessary or that have little to no apparent usage,
180 and it also includes some performance optimizations.
181
182 Specifically, initializing or updating a bidict
183 is now up to 70% faster in microbenchmarks.
184
185 The changes in this release will also make it easier
186 to maintain and improve bidict in the future,
187 including further potential performance optimizations.
188
189 It also contains several other improvements.
190
191 - Drop support for Python 3.7,
192 which reached end of life on 2023-06-27,
193 and take advantage of features available in Python 3.8+.
194
195 - Remove ``FrozenOrderedBidict`` now that Python 3.7 is no longer supported.
196 :class:`~bidict.frozenbidict` now provides everything
197 that ``FrozenOrderedBidict`` provided
198 (including :class:`reversibility <collections.abc.Reversible>`)
199 on all supported Python versions,
200 but with less space overhead.
201
202 - Remove ``namedbidict`` due to low usage.
203
204 - Remove the ``kv`` field of :class:`~bidict.OnDup`
205 which specified the :class:`~bidict.OnDupAction` to take
206 in the case of :ref:`basic-usage:key and value duplication`.
207 The :attr:`~bidict.OnDup.val` field now specifies the action to take
208 in the case of
209 :ref:`basic-usage:key and value duplication`
210 as well as
211 :ref:`just value duplication <basic-usage:values must be unique>`.
212
213 - Improve type hints for the
214 :attr:`~bidict.BidictBase.inv` shortcut alias
215 for :attr:`~bidict.BidictBase.inverse`.
216
217 - Fix a bug where calls like
218 ``bidict(None)``, ``bi.update(False)``, etc.
219 would fail to raise a :class:`TypeError`.
220
221 - All :meth:`~bidict.BidictBase.__init__`,
222 :meth:`~bidict.MutableBidict.update`,
223 and related methods
224 now handle `SupportsKeysAndGetItem
225 <https://github.com/python/typeshed/blob/3eb9ff/stdlib/_typeshed/__init__.pyi#L128-L131>`__
226 objects that are not :class:`~collections.abc.Mapping`\s
227 the same way that `MutableMapping.update()
228 <https://github.com/python/cpython/blob/v3.11.5/Lib/_collections_abc.py#L943>`__ does,
229 before falling back to handling the provided object as an iterable of pairs.
230
231 - The :func:`repr` of ordered bidicts now matches that of regular bidicts,
232 e.g. ``OrderedBidict({1: 1})`` rather than ``OrderedBidict([(1, 1)])``.
233
234 (Accordingly, the ``bidict.__repr_delegate__`` field has been removed
235 now that it's no longer needed.)
236
237 This tracks with the change to :class:`collections.OrderedDict`\'s :func:`repr`
238 `in Python 3.12 <https://github.com/python/cpython/pull/101661>`__.
239
240 - Test with Python 3.12 in CI.
241
242 Note: Older versions of bidict also support Python 3.12,
243 even though they don't explicitly declare support for it.
244
245 - Drop use of `Trove classifiers <https://github.com/pypa/trove-classifiers>`__
246 that declare support for specific Python versions in package metadata.
247
248
249 0.22.1 (2022-12-31)
250 -------------------
251
252 - Only include the source code in the source distribution.
253 This reduces the size of the source distribution
254 from ~200kB to ~30kB.
255
256 - Fix the return type hint of :func:`bidict.inverted`
257 to return an :class:`~collections.abc.Iterator`,
258 rather than an :class:`~collections.abc.Iterable`.
259
260
261 0.22.0 (2022-03-23)
262 -------------------
263
264 - Drop support for Python 3.6, which reached end of life on 2021-12-23
265 and is no longer supported by pip as of pip version 22.
266 Take advantage of this to reduce bidict's maintenance costs.
267
268 - Use mypy-appeasing explicit re-exports in ``__init__.py``
269 (e.g. ``import x as x``)
270 so that mypy no longer gives you an implicit re-export error
271 if you run it with ``--no-implicit-reexport`` (or ``--strict``)
272 against code that imports from :mod:`bidict`.
273
274 - Update the implementations and type annotations of
275 :meth:`bidict.BidictBase.keys` and
276 :meth:`bidict.BidictBase.values` to make use of the new
277 :class:`~bidict.BidictKeysView` type,
278 which works a bit better with type checkers.
279
280 - Inverse bidict instances are now computed lazily the first time
281 the :attr:`~bidict.BidictBase.inverse` attribute is accessed
282 rather than being computed eagerly during initialization.
283 (A bidict's backing, inverse, one-way mapping
284 is still kept in sync eagerly as any mutations are made,
285 to preserve key- and value-uniqueness.)
286
287 - Optimize initializing a bidict with another bidict.
288 In a microbenchmark on Python 3.10,
289 this now performs over **2x faster**.
290
291 - Optimize updating an empty bidict with another bidict.
292 In a microbenchmark on Python 3.10,
293 this now performs **60-75% faster**.
294
295 - Optimize :meth:`~bidict.BidictBase.copy`.
296 In a microbenchmark on Python 3.10,
297 this now performs **10-20x faster**.
298
299 - Optimize rolling back
300 :ref:`failed updates to a bidict <basic-usage:Updates Fail Clean>`
301 in the case that the number of items passed to the update call
302 can be determined to be larger than the bidict being updated.
303 Previously this rollback was O(n) in the number of items passed.
304 Now it is O(1), i.e. **unboundedly faster**.
305
306 - Optimize :meth:`bidict.BidictBase.__contains__`
307 (the method called when you run ``key in mybidict``).
308 In a microbenchmark on Python 3.10,
309 this now performs over **3-10x faster** in the False case,
310 and at least **50% faster** in the True case.
311
312 - Optimize :meth:`bidict.BidictBase.__eq__`
313 (the method called when you run ``mybidict == other``).
314 In a microbenchmark on Python 3.10,
315 this now performs **15-25x faster** for ordered bidicts,
316 and **7-12x faster** for unordered bidicts.
317
318 - Optimize :meth:`~bidict.BidictBase.equals_order_sensitive`.
319 In a microbenchmark on Python 3.10,
320 this now performs **2x faster** for ordered bidicts
321 and **60-90% faster** for unordered bidicts.
322
323 - Optimize the
324 :class:`~collections.abc.MappingView` objects returned by
325 :meth:`bidict.OrderedBidict.keys <bidict.OrderedBidictBase.keys>`,
326 :meth:`bidict.OrderedBidict.values <bidict.BidictBase.values>`, and
327 :meth:`bidict.OrderedBidict.items <bidict.OrderedBidictBase.items>`
328 to delegate to backing ``dict_keys`` and ``dict_items``
329 objects if available, which are much faster in CPython.
330 For example, in a microbenchmark on Python 3.10,
331 ``orderedbi.items() == d.items()``
332 now performs **30-50x faster**.
333
334 - Fix a bug where
335 :meth:`bidict.BidictBase.__eq__` was always returning False
336 rather than :obj:`NotImplemented`
337 in the case that the argument was not a
338 :class:`~collections.abc.Mapping`,
339 defeating the argument's own ``__eq__()`` if implemented.
340 As a notable example, bidicts now correctly compare equal to
341 :obj:`unittest.mock.ANY`.
342
343 - :class:`bidict.BidictBase` now adds a ``__reversed__`` implementation
344 to subclasses that don't have an overridden implementation
345 depending on whether both their backing mappings are
346 :class:`~collections.abc.Reversible`.
347 Previously, a ``__reversed__`` implementation was only added to
348 :class:`~bidict.BidictBase` when ``BidictBase._fwdm_cls`` was
349 :class:`~collections.abc.Reversible`.
350 So if a :class:`~bidict.BidictBase` subclass set its ``_fwdm_cls``
351 to a non-reversible mutable mapping,
352 it would also have to manually set its ``__reversed__`` attribute to None
353 to override the implementation inherited from :class:`~bidict.BidictBase`.
354 This is no longer necessary thanks to bidict's new
355 :meth:`object.__init_subclass__` logic.
356
357 - The
358 :class:`~collections.abc.MappingView` objects
359 returned by
360 :meth:`bidict.OrderedBidict.keys <bidict.OrderedBidictBase.keys>`,
361 :meth:`bidict.OrderedBidict.values <bidict.BidictBase.values>`, and
362 :meth:`bidict.OrderedBidict.items <bidict.OrderedBidictBase.items>`
363 are now
364 :class:`~collections.abc.Reversible`.
365 (This was already the case for unordered bidicts
366 when running on Python 3.8+.)
367
368 - Add support for Python 3.9-style dict merge operators
369 (`PEP 584 <https://www.python.org/dev/peps/pep-0584/>`__).
370
371 See `the tests <https://github.com/jab/bidict/blob/main/tests/>`__
372 for examples.
373
374 - Update docstrings for
375 :meth:`bidict.BidictBase.keys`,
376 :meth:`bidict.BidictBase.values`, and
377 :meth:`bidict.BidictBase.items`
378 to include more details.
379
380 - ``namedbidict`` now
381 exposes the passed-in *keyname* and *valname*
382 in the corresponding properties on the generated class.
383
384 - ``namedbidict`` now requires *base_type*
385 to be a subclass of :class:`~bidict.BidictBase`,
386 but no longer requires *base_type* to provide
387 an ``_isinv`` attribute,
388 which :class:`~bidict.BidictBase` subclasses no longer provide.
389
390 - When attempting to pickle a bidict's inverse whose class was
391 :ref:`dynamically generated
392 <extending:Dynamic Inverse Class Generation>`,
393 and no reference to the dynamically-generated class has been stored
394 anywhere in :data:`sys.modules` where :mod:`pickle` can find it,
395 the pickle call is now more likely to succeed
396 rather than failing with a :class:`~pickle.PicklingError`.
397
398 - Remove the use of slots from (non-ABC) bidict types.
399
400 This better matches the mapping implementations in Python's standard library,
401 and significantly reduces code complexity and maintenance burden.
402 The memory savings conferred by using slots are not noticeable
403 unless you're creating millions of bidict instances anyway,
404 which is an extremely unusual usage pattern.
405
406 Of course, bidicts can still contain millions (or more) items
407 (which is not an unusual usage pattern)
408 without using any more memory than before these changes.
409 Notably, slots are still used in the internal linked list nodes of ordered bidicts
410 to save memory, since as many node instances are created as there are items inserted.
411
412
413 0.21.4 (2021-10-23)
414 -------------------
415
416 Explicitly declare support for Python 3.10
417 as well as some minor internal improvements.
418
419
420 0.21.3 (2021-09-05)
421 -------------------
422
423 - All bidicts now provide the :meth:`~bidict.BidictBase.equals_order_sensitive` method,
424 not just :class:`~bidict.OrderedBidict`\s.
425
426 Since support for Python < 3.6 was dropped in v0.21.0,
427 :class:`dict`\s provide a deterministic ordering
428 on all supported Python versions,
429 and as a result, all bidicts do too.
430 So now even non-:class:`Ordered <bidict.OrderedBidict>` bidicts
431 might as well provide :meth:`~bidict.BidictBase.equals_order_sensitive`.
432
433 See the updated
434 :ref:`other-bidict-types:What about order-preserving dicts?` docs for more info.
435
436 - Take better advantage of the fact that dicts became
437 :class:`reversible <collections.abc.Reversible>` in Python 3.8.
438
439 Specifically, now even non-:class:`Ordered <bidict.OrderedBidict>` bidicts
440 provide a :meth:`~bidict.BidictBase.__reversed__` implementation on Python 3.8+
441 that calls :func:`reversed` on the backing ``_fwdm`` mapping.
442
443 As a result, if you are using Python 3.8+,
444 :class:`~bidict.frozenbidict` now gives you everything that
445 ``FrozenOrderedBidict`` gives you,
446 but with less space overhead.
447
448 - Drop `setuptools_scm <https://github.com/pypa/setuptools_scm>`__
449 as a ``setup_requires`` dependency.
450
451 - Remove the ``bidict.__version_info__`` attribute.
452
453
454 0.21.2 (2020-09-07)
455 -------------------
456
457 - Include `py.typed <https://www.python.org/dev/peps/pep-0561/#packaging-type-information>`__
458 file to mark :mod:`bidict` as type hinted.
459
460
461 0.21.1 (2020-09-07)
462 -------------------
463
464 This release was yanked and replaced with the 0.21.2 release,
465 which actually provides the intended changes.
466
467
468 0.21.0 (2020-08-22)
469 -------------------
470
471 - :mod:`bidict` now provides
472 `type hints <https://www.python.org/dev/peps/pep-0484/>`__! ⌨️ ✅
473
474 Adding type hints to :mod:`bidict` poses particularly interesting challenges
475 due to the combination of generic types,
476 dynamically-generated types
477 (such as :ref:`inverse bidict classes <extending:Dynamic Inverse Class Generation>`
478 and ``namedbidict``\s),
479 and complicating optimizations
480 such as the use of slots and weakrefs.
481
482 It didn't take long to hit bugs and missing features
483 in the state of the art for type hinting in Python today,
484 e.g. missing higher-kinded types support
485 (`python/typing#548 <https://github.com/python/typing/issues/548#issuecomment-621195693>`__),
486 too-narrow type hints for :class:`collections.abc.Mapping`
487 (`python/typeshed#4435 <https://github.com/python/typeshed/issues/4435>`__),
488 a :class:`typing.Generic` bug in Python 3.6
489 (`BPO-41451 <https://bugs.python.org/issue41451>`__), etc.
490
491 That said, this release should provide a solid foundation
492 for code using :mod:`bidict` that enables static type checking.
493
494 As always, if you spot any opportunities to improve :mod:`bidict`
495 (including its new type hints),
496 please don't hesitate to submit a PR!
497
498 - Add :class:`bidict.MutableBidirectionalMapping` ABC.
499
500 The :ref:`other-bidict-types:Bidict Types Diagram` has been updated accordingly.
501
502 - Drop support for Python 3.5,
503 which reaches end of life on 2020-09-13,
504 represents a tiny percentage of bidict downloads on
505 `PyPI Stats <https://pypistats.org/packages/bidict>`__,
506 and lacks support for
507 `variable type hint syntax <https://www.python.org/dev/peps/pep-0526/>`__,
508 `ordered dicts <https://stackoverflow.com/a/39980744>`__,
509 and :attr:`object.__init_subclass__`.
510
511 - Remove the no-longer-needed ``bidict.compat`` module.
512
513 - Move :ref:`inverse bidict class access <extending:Dynamic Inverse Class Generation>`
514 from a property to an attribute set in
515 :attr:`~bidict.BidictBase.__init_subclass__`,
516 to save function call overhead on repeated access.
517
518 - :meth:`bidict.OrderedBidictBase.__iter__` no longer accepts
519 a ``reverse`` keyword argument so that it matches the signature of
520 :meth:`container.__iter__`.
521
522 - Set the ``__module__`` attribute of various :mod:`bidict` types
523 (using :func:`sys._getframe` when necessary)
524 so that private, internal modules are not exposed
525 e.g. in classes' repr strings.
526
527 - ``namedbidict`` now immediately raises :class:`TypeError`
528 if the provided ``base_type`` does not provide
529 ``_isinv`` or :meth:`~object.__getstate__`,
530 rather than succeeding with a class whose instances may raise
531 :class:`AttributeError` when these attributes are accessed.
532
533
534 0.20.0 (2020-07-23)
535 -------------------
536
537 The following breaking changes are expected to affect few if any users.
538
539 Remove APIs deprecated in the previous release:
540
541 - ``bidict.OVERWRITE`` and ``bidict.IGNORE``.
542
543 - The ``on_dup_key``, ``on_dup_val``, and ``on_dup_kv`` arguments of
544 :meth:`~bidict.MutableBidict.put` and :meth:`~bidict.MutableBidict.putall`.
545
546 - The ``on_dup_key``, ``on_dup_val``, and ``on_dup_kv``
547 :class:`~bidict.bidict` class attributes.
548
549 - Remove ``bidict.BidirectionalMapping.__subclasshook__``
550 due to lack of use and maintenance cost.
551
552 Fixes a bug introduced in 0.15.0
553 that caused any class with an ``inverse`` attribute
554 to be incorrectly considered a subclass of :class:`collections.abc.Mapping`.
555 :issue:`111`
556
557
558 0.19.0 (2020-01-09)
559 -------------------
560
561 - Drop support for Python 2
562 :ref:`as promised in v0.18.2 <changelog:0.18.2 (2019-09-08)>`.
563
564 The ``bidict.compat`` module has been pruned accordingly.
565
566 This makes bidict more efficient on Python 3
567 and enables further improvement to bidict in the future.
568
569 - Deprecate ``bidict.OVERWRITE`` and ``bidict.IGNORE``.
570 A :class:`UserWarning` will now be emitted if these are used.
571
572 :attr:`bidict.DROP_OLD` and :attr:`bidict.DROP_NEW` should be used instead.
573
574 - Rename ``DuplicationPolicy`` to :class:`~bidict.OnDupAction`
575 (and implement it via an :class:`~enum.Enum`).
576
577 An :class:`~bidict.OnDupAction` may be one of
578 :attr:`~bidict.RAISE`,
579 :attr:`~bidict.DROP_OLD`, or
580 :attr:`~bidict.DROP_NEW`.
581
582 - Expose the new :class:`~bidict.OnDup` class
583 to contain the three :class:`~bidict.OnDupAction`\s
584 that should be taken upon encountering
585 the three kinds of duplication that can occur
586 (*key*, *val*, *kv*).
587
588 - Provide the
589 :attr:`~bidict.ON_DUP_DEFAULT`,
590 :attr:`~bidict.ON_DUP_RAISE`, and
591 :attr:`~bidict.ON_DUP_DROP_OLD`
592 :class:`~bidict.OnDup` convenience instances.
593
594 - Deprecate the
595 ``on_dup_key``, ``on_dup_val``, and ``on_dup_kv`` arguments
596 of :meth:`~bidict.MutableBidict.put` and :meth:`~bidict.MutableBidict.putall`.
597 A :class:`UserWarning` will now be emitted if these are used.
598
599 These have been subsumed by the new *on_dup* argument,
600 which takes an :class:`~bidict.OnDup` instance.
601
602 Use it like this: ``bi.put(1, 2, OnDup(key=RAISE, val=...))``.
603 Or pass one of the instances already provided,
604 such as :attr:`~bidict.ON_DUP_DROP_OLD`.
605 Or just don't pass an *on_dup* argument
606 to use the default value of :attr:`~bidict.ON_DUP_RAISE`.
607
608 The :ref:`basic-usage:Values Must Be Unique` docs
609 have been updated accordingly.
610
611 - Deprecate the
612 ``on_dup_key``, ``on_dup_val``, and ``on_dup_kv``
613 :class:`~bidict.bidict` class attributes.
614 A :class:`UserWarning` will now be emitted if these are used.
615
616 These have been subsumed by the new
617 :attr:`~bidict.BidictBase.on_dup` class attribute,
618 which takes an :class:`~bidict.OnDup` instance.
619
620 See the updated :doc:`extending` docs for example usage.
621
622 - Improve the more efficient implementations of
623 ``bidict.BidirectionalMapping.keys``,
624 ``bidict.BidirectionalMapping.values``, and
625 ``bidict.BidirectionalMapping.items``,
626 and now also provide a more efficient implementation of
627 ``bidict.BidirectionalMapping.__iter__``
628 by delegating to backing :class:`dict`\s
629 in the bidict types for which this is possible.
630
631 - Move
632 :meth:`bidict.BidictBase.values` to
633 ``bidict.BidirectionalMapping.values``,
634 since the implementation is generic.
635
636 - No longer use ``__all__`` in :mod:`bidict`'s ``__init__.py``.
637
638
639 0.18.4 (2020-11-02)
640 -------------------
641
642 - Backport fix from v0.20.0
643 that removes ``bidict.BidirectionalMapping.__subclasshook__``
644 due to lack of use and maintenance cost.
645
646
647 0.18.3 (2019-09-22)
648 -------------------
649
650 - Improve validation of names passed to ``namedbidict``:
651 Use :meth:`str.isidentifier` on Python 3,
652 and a better regex on Python 2.
653
654 - On Python 3,
655 set :attr:`~definition.__qualname__` on ``namedbidict`` classes
656 based on the provided ``typename`` argument.
657
658
659 0.18.2 (2019-09-08)
660 -------------------
661
662 - Warn that Python 2 support will be dropped in a future release
663 when Python 2 is detected.
664
665
666 0.18.1 (2019-09-03)
667 -------------------
668
669 - Fix a regression introduced by the memory optimizations added in 0.15.0
670 which caused
671 :func:`deepcopied <copy.deepcopy>` and
672 :func:`unpickled <pickle.loads>`
673 bidicts to have their inverses set incorrectly.
674 :issue:`94`
675
676
677 0.18.0 (2019-02-14)
678 -------------------
679
680 - Rename ``bidict.BidirectionalMapping.inv`` to :attr:`~bidict.BidirectionalMapping.inverse`
681 and make :attr:`bidict.BidictBase.inv` an alias for :attr:`~bidict.BidictBase.inverse`.
682 :issue:`86`
683
684 - ``bidict.BidirectionalMapping.__subclasshook__`` now requires an ``inverse`` attribute
685 rather than an ``inv`` attribute for a class to qualify as a virtual subclass.
686 This breaking change is expected to affect few if any users.
687
688 - Add Python 2/3-compatible ``bidict.compat.collections_abc`` alias.
689
690 - Stop testing Python 3.4 on CI,
691 and warn when Python 3 < 3.5 is detected
692 rather than Python 3 < 3.3.
693
694 Python 3.4 reaches `end of life <https://www.python.org/dev/peps/pep-0429/>`__ on 2019-03-18.
695 As of January 2019, 3.4 represents only about 3% of bidict downloads on
696 `PyPI Stats <https://pypistats.org/packages/bidict>`__.
697
698
699 0.17.5 (2018-11-19)
700 -------------------
701
702 Improvements to performance and delegation logic,
703 with minor breaking changes to semi-private APIs.
704
705 - Remove the ``__delegate__`` instance attribute added in the previous release.
706 It was overly general and not worth the cost.
707
708 Instead of checking ``self.__delegate__`` and delegating accordingly
709 each time a possibly-delegating method is called,
710 revert back to using "delegated-to-fwdm" mixin classes
711 (now found in ``bidict._delegating_mixins``),
712 and resurrect a mutable bidict parent class that omits the mixins
713 as :class:`bidict.MutableBidict`.
714
715 - Rename ``__repr_delegate__`` to ``_repr_delegate``.
716
717
718 0.17.4 (2018-11-14)
719 -------------------
720
721 Minor code, interop, and (semi-)private API improvements.
722
723 - :class:`~bidict.OrderedBidict` optimizations and code improvements.
724
725 Use ``bidict``\s for the backing ``_fwdm`` and ``_invm`` mappings,
726 obviating the need to store key and value data in linked list nodes.
727
728 - Refactor proxied- (i.e. delegated-) to-``_fwdm`` logic
729 for better composability and interoperability.
730
731 Drop the ``_Proxied*`` mixin classes
732 and instead move their methods
733 into :class:`~bidict.BidictBase`,
734 which now checks for an object defined by the
735 ``BidictBase.__delegate__`` attribute.
736 The ``BidictBase.__delegate__`` object
737 will be delegated to if the method is available on it,
738 otherwise a default implementation
739 (e.g. inherited from :class:`~collections.abc.Mapping`)
740 will be used otherwise.
741 Subclasses may set ``__delegate__ = None`` to opt out.
742
743 Consolidate ``_MutableBidict`` into :class:`bidict.bidict`
744 now that the dropped mixin classes make it unnecessary.
745
746 - Change ``__repr_delegate__``
747 to simply take a type like :class:`dict` or :class:`list`.
748
749 - Upgrade to latest major
750 `sortedcontainers <https://github.com/grantjenks/python-sortedcontainers>`__
751 version (from v1 to v2)
752 for the :ref:`extending:\`\`SortedBidict\`\` Recipes`.
753
754 - ``bidict.compat.{view,iter}{keys,values,items}`` on Python 2
755 no longer assumes the target object implements these methods,
756 as they're not actually part of the
757 :class:`~collections.abc.Mapping` interface,
758 and provides fallback implementations when the methods are unavailable.
759 This allows the :ref:`extending:\`\`SortedBidict\`\` Recipes`
760 to continue to work with sortedcontainers v2 on Python 2.
761
762
763 0.17.3 (2018-09-18)
764 -------------------
765
766 - Improve packaging by adding a pyproject.toml
767 and by including more supporting files in the distribution.
768 `#81 <https://github.com/jab/bidict/pull/81>`__
769
770 - Drop pytest-runner and support for running tests via ``python setup.py test``
771 in preference to ``pytest`` or ``python -m pytest``.
772
773
774 0.17.2 (2018-04-30)
775 -------------------
776
777 **Memory usage improvements**
778
779 - Use less memory in the linked lists that back
780 :class:`~bidict.OrderedBidict`\s
781 by storing node data unpacked
782 rather than in (key, value) tuple objects.
783
784
785 0.17.1 (2018-04-28)
786 -------------------
787
788 **Bugfix Release**
789
790 Fix a regression in 0.17.0 that could cause erroneous behavior
791 when updating items of an :class:`~bidict.OrderedBidict`'s inverse,
792 e.g. ``some_ordered_bidict.inv[foo] = bar``.
793
794
795 0.17.0 (2018-04-25)
796 -------------------
797
798 **Speedups and memory usage improvements**
799
800 - Pass
801 :meth:`~bidict.BidictBase.keys`,
802 :meth:`~bidict.BidictBase.values`, and
803 :meth:`~bidict.BidictBase.items` calls
804 (as well as their ``iter*`` and ``view*`` counterparts on Python 2)
805 through to the backing ``_fwdm`` and ``_invm`` dicts
806 so that they run as fast as possible
807 (i.e. at C speed on CPython),
808 rather than using the slower implementations
809 inherited from :class:`collections.abc.Mapping`.
810
811 - Use weakrefs in the linked lists that back
812 :class:`~bidict.OrderedBidict`\s
813 to avoid creating strong reference cycles.
814
815 Memory for an ordered bidict that you create
816 can now be reclaimed in CPython
817 as soon as you no longer hold any references to it,
818 rather than having to wait until the next garbage collection.
819 `#71 <https://github.com/jab/bidict/pull/71>`__
820
821
822 **Misc**
823
824 - Add ``bidict.__version_info__`` attribute
825 to complement ``bidict.__version__``.
826
827
828 0.16.0 (2018-04-06)
829 -------------------
830
831 Minor code and efficiency improvements to
832 :func:`~bidict.inverted` and
833 ``bidict._iter._iteritems_args_kw``
834 (formerly ``bidict.pairs()``).
835
836
837 **Minor Breaking API Changes**
838
839 The following breaking changes are expected to affect few if any users.
840
841 - Rename ``bidict.pairs()`` → ``bidict._iter._iteritems_args_kw``.
842
843
844 0.15.0 (2018-03-29)
845 -------------------
846
847 **Speedups and memory usage improvements**
848
849 - Use :ref:`slots` to speed up bidict attribute access and reduce memory usage.
850 On Python 3,
851 instantiating a large number of bidicts now uses ~57% the amount of memory
852 that it used before,
853 and on Python 2 only ~33% the amount of memory that it used before,
854 in a simple but representative
855 `benchmark <https://github.com/jab/bidict/pull/56#issuecomment-368203591>`__.
856
857 - Use weakrefs to refer to a bidict's inverse internally,
858 no longer creating a strong reference cycle.
859 Memory for a bidict that you create can now be reclaimed
860 in CPython as soon as you no longer hold any references to it,
861 rather than having to wait for the next garbage collection.
862 See the new
863 :ref:`addendum:\`\`bidict\`\` Avoids Reference Cycles`
864 documentation.
865 :issue:`24`
866
867 - Make :func:`bidict.BidictBase.__eq__` significantly
868 more speed- and memory-efficient when comparing to
869 a non-:class:`dict` :class:`~collections.abc.Mapping`.
870 (``Mapping.__eq__()``\'s inefficient implementation will now never be used.)
871 The implementation is now more reusable as well.
872
873 - Make :func:`bidict.OrderedBidictBase.__iter__` as well as
874 equality comparison slightly faster for ordered bidicts.
875
876 **Minor Bugfixes**
877
878 - ``namedbidict`` now verifies that the provided
879 ``keyname`` and ``valname`` are distinct,
880 raising :class:`ValueError` if they are equal.
881
882 - ``namedbidict`` now raises :class:`TypeError`
883 if the provided ``base_type``
884 is not a :class:`~bidict.BidirectionalMapping`.
885
886 - If you create a custom bidict subclass whose ``_fwdm_cls``
887 differs from its ``_invm_cls``
888 (as in the ``FwdKeySortedBidict`` example
889 from the :ref:`extending:\`\`SortedBidict\`\` Recipes`),
890 the inverse bidirectional mapping type
891 (with ``_fwdm_cls`` and ``_invm_cls`` swapped)
892 is now correctly computed and used automatically
893 for your custom bidict's
894 :attr:`~bidict.BidictBase.inverse` bidict.
895
896 **Misc**
897
898 - Classes no longer have to provide an ``__inverted__``
899 attribute to be considered virtual subclasses of
900 :class:`~bidict.BidirectionalMapping`.
901
902 - If :func:`bidict.inverted` is passed
903 an object with an ``__inverted__`` attribute,
904 it now ensures it is :func:`callable`
905 before returning the result of calling it.
906
907 - :func:`~bidict.BidictBase.__repr__` no longer checks for a ``__reversed__``
908 method to determine whether to use an ordered or unordered-style repr.
909 It now calls the new ``__repr_delegate__`` instead
910 (which may be overridden if needed), for better composability.
911
912 **Minor Breaking API Changes**
913
914 The following breaking changes are expected to affect few if any users.
915
916 - Split back out the :class:`~bidict.BidictBase` class
917 from :class:`~bidict.frozenbidict`
918 and :class:`~bidict.OrderedBidictBase`
919 from ``FrozenOrderedBidict``,
920 reverting the merging of these in 0.14.0.
921 Having e.g. ``issubclass(bidict, frozenbidict) == True`` was confusing,
922 so this change restores ``issubclass(bidict, frozenbidict) == False``.
923
924 See the updated :ref:`other-bidict-types:Bidict Types Diagram`
925 and :ref:`other-bidict-types:Polymorphism` documentation.
926
927 - Rename:
928
929 - ``bidict.BidictBase.fwdm`` → ``._fwdm``
930 - ``bidict.BidictBase.invm`` → ``._invm``
931 - ``bidict.BidictBase.fwd_cls`` → ``._fwdm_cls``
932 - ``bidict.BidictBase.inv_cls`` → ``._invm_cls``
933 - ``bidict.BidictBase.isinv`` → ``._isinv``
934
935 Though overriding ``_fwdm_cls`` and ``_invm_cls`` remains supported
936 (see :doc:`extending`),
937 this is not a common enough use case to warrant public names.
938 Most users do not need to know or care about any of these.
939
940 - The :attr:`~bidict.RAISE`,
941 ``OVERWRITE``, and ``IGNORE``
942 duplication policies are no longer available as attributes of
943 ``DuplicationPolicy``,
944 and can now only be accessed as attributes of
945 the :mod:`bidict` module namespace,
946 which was the canonical way to refer to them anyway.
947 It is now no longer possible to create an infinite chain like
948 ``DuplicationPolicy.RAISE.RAISE.RAISE...``
949
950 - Make ``bidict.pairs()`` and :func:`bidict.inverted`
951 no longer importable from ``bidict.util``,
952 and now only importable from the top-level :mod:`bidict` module.
953 (``bidict.util`` was renamed ``bidict._util``.)
954
955 - Pickling ordered bidicts now requires
956 at least version 2 of the pickle protocol.
957 If you are using Python 3,
958 :obj:`pickle.DEFAULT_PROTOCOL` is 3 anyway,
959 so this will not affect you.
960 However if you are using in Python 2,
961 :obj:`~pickle.DEFAULT_PROTOCOL` is 0,
962 so you must now explicitly specify the version
963 in your :func:`pickle.dumps` calls,
964 e.g. ``pickle.dumps(ob, 2)``.