Commit Graph

65 Commits

Author SHA1 Message Date
jab dd81c83c3f fix typo 2019-02-13 22:59:12 -05:00
jab 060a9c4039 prepare for v0.18.0 release 2019-02-13 20:05:15 -05:00
jab ce345d49ba Rename .inv to .inverse and add an alias for .inv.
bidict.BidirectionalMapping.__subclasshook__ now requires an ``inverse`` attribute
rather than an ``inv`` attribute for a class to qualify as a virtual subclass.

Closes #86.
2019-02-13 19:50:22 -05:00
jab 5f9cab9acf drop Py3.4 from Travis, update to latest flake8 + pydocstyle, improve lint_src spelling 2019-01-30 23:53:50 -05:00
jab a3fd16b6f7 Travis build improvements. 2018-12-30 15:03:42 -05:00
jab 36e28358dc improve hypothesis tests and .travis.yml, add compat.collections_abc and namedbidict.{_keyname,_valname} 2018-12-29 13:13:06 -05:00
jab d13fd9bb8a resurrect delegating mixins instead of __delegate__ + other refinements
e.g. s/__repr_delegate__/_repr_delegate

Also
- update
- update from pytest 3 to 4
- add CII best practices badge
- prepare for 0.17.5 release
2018-11-19 09:37:38 -05:00
jab e70816c6fa prepare for v0.17.4 release 2018-11-13 21:51:15 -05:00
jab ba6e1fff13 Add tests for better bidict.compat.{iter,view}* compatibility
No longer assume the target object implements these methods on Python 2.
Update compat autodocs.
2018-11-13 21:38:59 -05:00
jab 3a8339d29c OrderedBidict optimizations and code improvements.
Use bidicts for the backing ``_fwdm`` and ``_invm`` mappings,
obviating the need to store key and value data in linked list nodes.

Also drop the unnecessary ^ from the namedtuple identifier regexes.
2018-11-06 16:10:03 -05:00
jab afdf2f4f61 Various improvements.
- Refactor proxied- (i.e. delegated-) to-``_fwdm`` logic
  for better composability and interoperability.

  Drop the ``_Proxied*`` mixin classes
  and instead move their methods
  into :class:`~bidict.BidictBase`,
  which now checks for an object defined by the
  :attr:`~bidict.BidictBase.__delegate__` attribute.
  The :attr:`~bidict.BidictBase.__delegate__` object
  will be delegated to if the method is available on it,
  otherwise a default implementation
  (e.g. inherited from :class:`~collections.abc.Mapping`)
  will be used otherwise.
  Subclasses may set ``__delegate__ = None`` to opt out.

- Consolidate ``_MutableBidict`` into :class:`bidict.bidict`
  now that the dropped mixin classes make it unnecessary.

- Change :attr:`~bidict.BidictBase.__repr_delegate__`
  to take simply a type like :class:`dict` or :class:`list`.

- Upgrade to latest major
  `sortedcontainers <https://github.com/grantjenks/python-sortedcontainers>`__
  version (from v1 to v2)
  for the :ref:`extending:Sorted Bidict Recipes`.

- ``bidict.compat.{view,iter}{keys,values,items}`` on Python2
  no longer assumes the target object implements these methods,
  as they're not actually part of the
  :class:`~collections.abc.Mapping` interface,
  and provides fallback implementations when the methods are unavailable.
  This allows the :ref:`extending:Sorted Bidict Recipes`
  to continue to work with sortedcontainers v2 on Python2.

- Test code in docs via Sphinx rather than pytest.

  Enables running Python version-dependent tests conditionally
  rather than skipping them altogether, as well as hiding import
  statements (via `testsetup`) that otherwise just add noise.

  Run tests (viz. pytest and Sphinx doctest) via a new
  run-tests.py script.
2018-11-05 15:52:59 -05:00
jab 43d6aaef92 update changelog in preparation for 0.17.3 release 2018-09-18 16:55:54 -04:00
jab b96699e3c6 update changelog and setup.cfg 2018-09-17 20:03:52 -04:00
jab 1f97e41326 update thanks 2018-09-17 19:35:35 -04:00
jab 1f5a66c355 improvements to pyproject.toml changes 2018-09-17 19:23:46 -04:00
jab c7c0357503 update changelog 2018-08-17 00:22:17 -04:00
jab ea9daf7b2f Use less memory in OrderedBidict, v0.17.2
- Use less memory in the linked lists that back bidict.OrderedBidict
  by storing node data unpacked rather than in (key, value) tuple objects.
- New _Sentinel subclass of _Node improves over old _make_sentinel code.
2018-04-30 12:18:42 +08:00
jab 5269abe6f8 prepare for v0.17.1 release 2018-04-28 11:05:57 +08:00
jab 6faf1ef03f Fix updating orderedbidict.inv 2018-04-28 09:50:29 +08:00
jab 7972aa1998 prepare for v0.17.0 release 2018-04-25 23:29:54 +07:00
jab 163667d5b4 optimize implementations of keys, values, and items
- Also refactor and improve hypothesis tests.
- Add a test that ordered bidict nodes have no reference cycles.
- Enable coverage on Travis for PyPy 2 now that there is a code path
  that is only taken on PyPy 2 (for FrozenOrderedBidict.iteritems).
- Restore running tests on Travis for all commits, not just for master.
- Docs:
  - OrderedBidict: "What if my Python version has order-preserving dicts?"
  - Equivalent but distinct Hashables: better code example demonstrating
    that this even occurs with a bidict and its own inverse.
2018-04-25 21:34:27 +07:00
jab a818b69aa0 refactor OrderedBidictBase, use weakrefs in nodes 2018-04-22 05:09:36 +07:00
jab cb1d80c97c tweak docs, setup.py, travis, and hypothesis tests
- improve basic usage and "Why can't I just use a dict?" docs
- rename _static -> assets
- use forward declarations of custom rst interpreted text roles we use that
  sphinx defines and that PyPI and GitHub couldn't handle otherwise (e.g.
  :doc:), rather than stripping them out in setup.py
- move __keywords__ and __url__ from setup.py into bidict/metadata.py
- add __version_info__ metadata attribute
- import bidict/metadata.py in setup.py rather than `exec`ing it
- add back Python 3.4 to Travis test matrix
- improve hypothesis settings for max_examples_5000 profile
  (used in nightly CI builds)
- suppress hypothesis's hung_test health check for max_examples_5000 profile
  to prevent flaky tests caused by failed health checks. Avoids errors like:

    E   hypothesis.errors.FailedHealthCheck: Your test has been running for
        at least five minutes. This is probably not what you intended, so by
        default Hypothesis turns it into an error.
    E   See https://hypothesis.readthedocs.io/en/latest/healthchecks.html for
        more information about this. If you want to disable just this health
        check, add HealthCheck.hung_test to the suppress_health_check settings
        for this test.
2018-04-19 15:52:02 +07:00
jab 7d2b5912a8 prepare for v0.16.0 release 2018-04-06 11:32:00 +07:00
jab 543d517ad9 bidict.pairs -> _iteritems_args_kw, docs + other small improvements
- improve coverage
- use latest pip on travis
- update to tox 3
- guard Python < 3.3 warning with PYMAJOR == 3 condition
- docs improvements, esp. for viewing on GitHub:
  - fix `foo <bar>`__ link syntax (always use two underscores)
  - use `.. code: python` for code blocks to enable GitHub syntax highlighting
  - ditch `.. include::` which GitHub does not support
  - use sphinx.ext.autosectionlabel
  - only wrap linkcheck with travis_retry
  - s/sibbell/libraries.io
2018-04-06 11:28:44 +07:00
jab 0f8897e926 prepare for v0.15.0 release 2018-03-29 10:11:32 +07:00
jab 2c031f9cf0 revert back to izip, don't assume pkg_resources available, docs and code tweaks 2018-03-26 20:04:53 +08:00
jab 410e20acc1 update changelog post-0.15.0rc1 tag 2018-03-02 12:59:15 +11:00
jab 807af7a541 prepare for v0.15.0rc1 release 2018-03-02 12:51:47 +11:00
jab f2cd4edc82 .compat.izip -> zip, BidirectionalMapping.inv -> abstractproperty, docs, tests 2018-03-01 22:40:53 +11:00
jab 629481ec15 improve BidirectionalMapping.__subclasshook__, .compat, .util->._util, docs, tests, lint
- Implement BidirectionalMapping.__subclasshook__ in terms of
  Mapping.__subclasshook__ to simplify and correct its implementation.
- Add new test_class_relationships.py tests.
- Import collections ABCs from .compat. Importing them directly from
  collections was deprecated and will stop working in Python 3.8.
  In Python 2 collections.abc does not exist.
- rename util.py -> _util.py
2018-03-01 14:18:39 +11:00
jab bfb6ed2a3b finish refactoring, misc. bugfixes, improve docs + tests 2018-02-28 00:09:57 +11:00
jab 4234bf8ce3 split back out (Ordered)BidictBase classes, improve namedbidict validation, docs 2018-02-27 10:29:56 +11:00
jab aa704b3d6e improve hypothesis tests, use of setuptools_scm and linting 2018-02-26 10:44:21 +11:00
jab 423f60e026 improve docs 2018-02-24 20:14:42 +11:00
jab 456f247b1d numerous code improvements
- Refactor _dedup_item, _write_item, and _undo_write methods to use
  higher-level abstractions (_DedupResult and _WriteResult classes).
- Add internal _OnDup class to bundle (on_dup_key, on_dup_val, on_dup_kv)
  together into a single abstraction. Signatures of methods like _put and
  _update are cleaner as a result.
- Add the "_NOOP" _DedupResult abstraction.
- Make _Marker extend namedtuple, no need for it to be mutable.
- Enable the pylint messages that were disabled now that the code is cleaner.
- Make DuplicationPolicy extend _Marker and make RAISE, OVERWRITE, and
  IGNORE instances of DuplicationPolicy once again. This time deprecate
  access via DuplicationPolicy.(IGNORE|RAISE|OVERWRITE) to prevent
  infinite chaining.
- Misc. code and docs improvements.
2018-02-20 21:23:04 +11:00
jab 02dcb49329 improve code comments and APIs (give APIs that should be private a leading _) 2018-02-20 00:07:14 +11:00
jab f1749540cb improve namedbidict
- raise TypeError if base_type is not a frozenbidict subclass
- rewrite the code to be clearer
2018-02-19 16:57:42 +11:00
jab 4d906b6eca code and documentation improvements
- Use __slots__ to speed up attribute access and decrease memory usage
  (adding _SlotPickleMixin to preserve pickleability)
- "Code review nav" comments
- Remove _clear from frozenbidict, leaving only the public `clear` methods on
  the mutable bidict types. Much clearer now! (ducks)
- Improve `pop` and `popitem` signatures. No need for them to take *args/**kw.
- Make bidict extend MutableMapping directly rather than registering it as a
  virtual subclass. Leave a comment explaining that it inherits
  MutableMapping's setdefault implementation now that it isn't added manually.
- Make the DuplicationPolicy class just a namespace holding
  RAISE, OVERWRITE, and IGNORE, not a _Marker itself.
  Make RAISE, OVERWRITE, and IGNORE just _Markers, not `DuplicationPolicy`s.
- Various other code and docs improvements.
2018-02-19 13:40:01 +11:00
jab 24b3d9b7dc various improvements
- Make :func:`bidict.FrozenOrderedBidict.__iter__` slightly more efficient.

- :func:`~bidict.frozenbidict.__repr__` no longer dynamically checks
  for a ``__reversed__`` method to determine whether to use an ordered or
  unordered ``__repr__`` delegate. Now it always just calls the new
  :func:`~bidict.frozenbidict.__repr_delegate__` instead, which may be
  explicitly overridden as needed.
2018-02-13 12:34:33 +11:00
jab 256270489a tweak inv-avoids-reference-cycles docs 2018-01-16 19:43:39 -05:00
jab 1ecc50a32c improve __inverted__ logic, docs
- 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.
2018-01-09 12:08:58 -05:00
jab 958ca8570a use more concise :role:`~foo.bar` sphinx link syntax
+ other small docs improvements
2018-01-02 16:49:34 -05:00
jab fc89808af7 docs 2017-12-17 13:58:57 -05:00
jab fb32b56de1 Fix #24 + other improvements.
- Use weakrefs to refer to a bidict's inverse to no longer create a reference
  cycle. Fixes #24.
- Rename fwd_cls to fwdm_cls.
- Rename inv_cls to invm_cls.
- inv_cls now returns the inverse class of the bidict, not its invm mapping.
- Rename isinv to _isinv.
2017-12-07 12:57:01 -05:00
jab ea93911f93 numerous improvements
- Make initializing (or updating an empty bidict) from only another
  BidirectionalMapping more efficient (skip dup checking).

- Fix accidental ignoring of specified base_type when (un)pickling
  namedbidicts.

- Fix incorrect inversion of some_named_bidict.inv.[fwdname]_for
  and some_named_bidict.inv.[invname]_for

- Only warn when unsupported Python version is detected.

- More tests.
2017-12-06 14:22:32 -05:00
jab 79894c28ba prepare for 0.14.1 release 2017-11-28 21:27:36 -05:00
jab 821c6a814c fix TypeError on b.viewitems() 2017-11-28 20:56:50 -05:00
jab 57b7ec117f fix AttributeError on `hash(frozenbidict().inv)` due to missing _hash attr 2017-11-28 20:36:39 -05:00
jab 06144d0c0f prepare for v0.14.0 release 2017-11-20 23:49:14 -05:00