Commit Graph

128 Commits

Author SHA1 Message Date
Joshua Bronson 2bee83b0d6 OrderedBidict pickling + minor code improvements
- Ensure that (un)pickling OrderedBidicts is order-preserving.
- Refactor __reduce__, _reduce_factory, and _init_from
  to use new private constructor _from_other.
- NamedBidictBase and GeneratedBidictInverse marker classes
  don't need to derive from BidictBase.
2022-02-16 10:38:37 -05:00
Joshua Bronson b5c9f346ce (c) 2022-02-15 15:37:25 -05:00
Joshua Bronson a239aa7917 Minor refactor. 2022-02-13 11:49:12 -05:00
Joshua Bronson 4f12c7f9eb Refine proxy logic for _OrderedBidictKeysView and _OrderedBidictItemsView 2022-02-12 14:59:03 -05:00
Joshua Bronson 5504a54bba Minor updates. 2022-02-11 16:59:06 -05:00
Joshua Bronson 2ab42ade03 Minor improvements, mostly to docs.
- Switch to Furo theme.
- Fix some links reported as broken by Sphinx's `make linkcheck`.
- No longer use autodoc private members. Avoids noisy Sphinx warnings.
- No longer generate duplicate section labels in Changelog.
  Avoids noisy Sphinx warnings.
- Remove logo, codecov badge, and add num-sponsors badge.
- Rename bidict._iter.iteritems_args_kw -> ...iteritems_args
2022-02-10 11:44:57 -05:00
Joshua Bronson a488b54334 Benchmarks, etc. 2022-02-09 11:56:57 -05:00
Joshua Bronson 1c9d7bec53 Minor code and docs changes. 2022-02-07 11:42:09 -05:00
Joshua Bronson 03d6cbc118 Compute inverse lazily, automatically add or remove __reversed__ implementations for BidictBase subclasses based on whether their backing mappings are reversible, improve mechanism for automatic dynamic generation of inverse bidict classes and use this for namedbidict, improve pickling. 2022-02-06 12:28:12 -05:00
Joshua Bronson 2057c40c69 Refactor OrderedBidictBase._node_by_key/val to node_by_korv 2022-02-02 22:52:19 -05:00
Joshua Bronson f1493e0778 Use one_of rather than sampled_from in hypothesis tests. 2022-02-02 16:55:04 -05:00
Joshua Bronson 6be66a1e0b Refactor for better performance, code quality, and maintainability. 2022-02-02 14:58:06 -05:00
Joshua Bronson 5dc6d98381 Redesign OrderedBidict for better performance and code reuse. 2022-01-31 16:45:46 -05:00
Joshua Bronson 12a9acabb7 Improvements to bidict view methods and docs. 2022-01-06 19:54:46 -05:00
Joshua Bronson 2598ccb70d rename tests/properties -> tests/property_tests 2022-01-05 19:37:59 -05:00
Joshua Bronson 69b83ff8b4 Add support for PEP 584-style dict merge operators. 2022-01-05 14:25:33 -05:00
Joshua Bronson 4fd2ffeebf Minor test improvements. 2022-01-05 12:29:35 -05:00
Joshua Bronson 7bcd478576 Remove use of slots from (non-ABC) bidict types.
Better matches mapping implementations in stdlib collections,
and saves considerable complexity and maintenance burden.
2022-01-03 18:27:00 -05:00
Joshua Bronson da250abf3e pyupgrade --py37-plus
Delete utf-8 encoding cookies from all files that require Python 3+,
where utf-8 is already the default.
2022-01-01 20:36:50 -05:00
Joshua Bronson f86ba703e4 Update copyright notices for 2022. 2022-01-01 12:59:11 -05:00
Joshua Bronson f8f896e361 Add property-based tests for keys(), values(), items() 2021-12-30 11:58:59 -05:00
Joshua Bronson c0c158a41c rm obsolete tests for Python 2 APIs 2021-12-30 10:59:38 -05:00
Joshua Bronson 9fcc793bfa Prepare for 0.21.3 release 2021-09-05 11:25:30 -04:00
Joshua Bronson e3533c77eb All bidicts provide __reversed__ in Python 3.8+ 2021-09-05 10:57:07 -04:00
Joshua Bronson 89cb936edb Move equals_order_sensitive into BidictBase. 2021-09-05 10:10:26 -04:00
Joshua Bronson bc8c9984fc Update copyright notices for 2021. 2021-01-01 12:14:24 -05:00
Joshua Bronson 11567533fe Move CI to GitHub Actions, fix version typo in metadata.py 2020-12-20 10:50:41 -05:00
leonidgman 7e4c8f2f66 Add pbt's for duplication errors (#116) 2020-09-27 19:37:37 -04:00
Joshua Bronson c1f9403d47 Add pbt: test_cleared_bidicts_have_no_items (#116) 2020-09-27 13:39:47 -04:00
Joshua Bronson 77b9faf9e9 Small docs + test improvements + prepare for new release. 2020-08-22 10:32:51 -04:00
Joshua Bronson 0ad5284f75 Finish first pass at adding type hints.
Fixes #93.
2020-08-12 10:22:25 -04:00
Joshua Bronson 8a8e58b51f f-strings 2020-08-01 09:54:45 -04:00
Joshua Bronson 01460c86a3 reduce noisy pylint comments 2020-08-01 09:44:24 -04:00
Joshua Bronson e62d85d933 Begin adding type hints, drop Python 3.5, rm bidict.compat 2020-08-01 09:31:15 -04:00
Joshua Bronson 2efdc0e7b8 Upgrade dependencies for various extras, precommit hooks, CI
Use a single job that runs all precommit hooks in CI
rather than separate jobs for flake8, pylint, pydocstyle, etc.
2020-07-29 21:59:45 -04:00
Joshua Bronson e2514160ec Add MutableBidirectionalMapping ABC 2020-07-26 16:33:25 -04:00
Joshua Bronson 5a4b6e99f4 Remove BidirectionalMapping.__subclasshook__
...due to lack of use and maintenance cost.

Fixes #111.
2020-07-23 09:37:53 -04:00
jab 9bb1d88383 rm PY2 vestige for namedbidict tests missed by #99. 2020-01-11 12:29:57 -05:00
jab fe269a351d Fix mis-ported @examples from 0ec3b8b.
Should make coverage more consistent again.
2020-01-10 21:49:04 -05:00
jab 9ade536188 rm IGNORE/OVERWRITE and on_dup_* compat code. 2020-01-08 21:48:51 -05:00
jab 0ec3b8b3e7 Various API changes and other improvements.
* Deprecate ``bidict.OVERWRITE`` and ``bidict.IGNORE``.
  A :class:`UserWarning` will now be emitted if these are used.

  :attr:`bidict.DROP_OLD` and :attr:`bidict.DROP_NEW` should be used instead.

* Rename ``DuplicationPolicy`` to :class:`~bidict.OnDupAction`
  (and implement it via an :class:`~enum.Enum`).

  A :class:`~bidict.OnDupAction` may be one of
  :attr:`~bidict.RAISE`,
  :attr:`~bidict.DROP_OLD`, or
  :attr:`~bidict.DROP_NEW`.

* Expose the new :class:`~bidict.OnDup` class,
  a named (*key*, *val*, *kv*) tuple of :class:`~bidict.OnDupAction`\s
  that should be taken upon encountering
  the 3 kinds of duplication that can occur.

* Provide the
  :attr:`~bidict.ON_DUP_DEFAULT`,
  :attr:`~bidict.ON_DUP_RAISE`, and
  :attr:`~bidict.ON_DUP_DROP_OLD`
  :class:`~bidict.OnDup` convenience instances.

* Deprecate the
  ``on_dup_key``, ``on_dup_val``, and ``on_dup_kv`` arguments
  of :meth:`~bidict.bidict.put` and :meth:`~bidict.bidict.putall`.
  A :class:`UserWarning` will now be emitted if these are used.

  They have been subsumed by the new *on_dup* argument,
  which takes an :class:`~bidict.OnDup` instance.
  Use it like this: ``bi.put(1, 2, OnDup(key=DROP_NEW))``.
  Or better yet, pass one of the
  ``ON_DUP_*`` convenience instances
  instead if possible.

  See the updated :ref:`basic-usage:Values Must Be Unique` docs for more info.

* Deprecate the
  ``on_dup_key``, ``on_dup_val``, and ``on_dup_kv``
  bidict class attributes.
  A :class:`UserWarning` will now be emitted if these are used.

  They have been subsumed by the new
  :attr:`~bidict.bidict.on_dup` class attribute,
  which takes an :class:`~bidict.OnDup` instance.

  See the updated :doc:`extending` docs for example usage.

* Move
  :meth:`bidict.BidictBase.values` to
  :meth:`bidict.BidirectionalMapping.values`,
  since the implementation is generic.

* No longer use ``__all__`` in ``bidict/__init__.py``.

* Cap max_size rather than disabling health checks and deadline as a
  less heavyhanded way to improve hypothesis test reliability on Travis.
2020-01-07 17:20:25 -05:00
jab d2b5adcce3 Happy 2020 🎉 2019-12-31 18:14:38 -05:00
jab a836f64aa4 Remove more Python 2 vestiges missed by #99. 2019-11-09 19:36:54 -05:00
jab cd73edd854 Remove Python 2 support.
Closes #97.
2019-11-03 21:54:54 -05:00
jab d925bd1c52 Add deterministic test cases for _undo_write.
Add deterministic inputs to test_putall_same_as_put_for_each_item via
@hypothesis.example(...) to ensure deterministic coverage of branches
in BidictBase._undo_write. Hypothesis doesn't always generate examples
that hit all the branches otherwise.
2019-11-03 21:05:46 -05:00
jab b207e1467a Improve Hypothesis tests.
- Initialize from iterables instead of lists of items in more places.
- Generate arbitrarily many items (rather than max 10).
- Don't include floats and text in HASHABLES. Slows example generation
  without actually finding more falsifying examples.
- Use simpler and more concise `st.tuples(...).map(...).filter(...)`
  constructions rather than much more complicated `st.composite`-based
  strategies.
- Simplify `test_iteritems_args_kw`.
- Split out more namedbidict tests so each one tests one thing.
- Use latest Travis pypy and pypy3.
- Only use a single Hypothesis profile ("custom"). Allow any of its
  settings that should be tunable to be tuned via dedicated env vars
  (currently just "HYPOTHESIS_MAX_EXAMPLES").
- Always turn off "too_slow" health check, not just for Travis cron builds.
  Never want a build to fail only because tests took too long.
- Set --hypothesis-verbosity="verbose" for Travis cron builds.
- Set --hypothesis-show-statistics for Travis cron builds.
2019-09-15 14:19:00 -04:00
jab ef7d75b488 Improve validation of names passed to namedbidict.
Use str.isidentifier on Python 3,
and a better regex on Python 2.

Revision 033083 (released in 0.15.0)
incorrectly replaced "A-Za-z" with "A-z" in the regex.
Also, "_" should always have been allowed
for the first character, but previously wasn't.
2019-09-08 17:43:57 -04:00
jab 38bef0eaa2 copy.copy and copy.deepcopy doctests 2019-09-03 10:26:35 -04:00
jab 94d42de53b Fix #94 - buggy unpickling and deepcopying.
Also fix some docs links broken in the previous commit.
2019-09-02 17:07:03 -04:00
jab 7a1069c35c Small improvements to tests, CI, docs + upgrades 2019-09-02 15:51:36 -04:00