squashed changes for 0.13.0
- support Python 3.6, refactor CI/test setup, increase test coverage
- refactor BidirectionalMapping, BidictBase, OrderedBidictBase,
FrozenBidictBase, and subclasses
- move frozenorderedbidict into _frozen and looseorderedbidict into _loose
- register bidict as a virtual subclass of MutableMapping rather than
inheriting from it directly. This makes it clearer that it does not use any
of the concrete generic methods that MutableMapping provides.
- improve performance and flexibility of frozenbidict and
frozenorderedbidict hashing
- docs, including new type-hierarchy.png diagram
- rm unused imap, ifilter, izip_longest from compat, add PYPY
- update to latest versions of dependencies
- restore benchmarking on travis
2017-01-09 15:37:31 +00:00
|
|
|
:class:`namedbidict <bidict.namedbidict>`
|
|
|
|
-----------------------------------------
|
2015-03-22 18:21:15 +00:00
|
|
|
|
2015-04-27 22:20:03 +00:00
|
|
|
:class:`bidict.namedbidict`,
|
|
|
|
inspired by :func:`collections.namedtuple`,
|
2015-03-22 18:21:15 +00:00
|
|
|
allows you to easily generate
|
|
|
|
a custom bidirectional map type
|
|
|
|
with custom attribute-based access to forward and inverse mappings::
|
|
|
|
|
2015-12-21 03:05:20 +00:00
|
|
|
>>> from bidict import namedbidict
|
2015-03-22 18:21:15 +00:00
|
|
|
>>> ElementMap = namedbidict('ElementMap', 'symbol', 'element')
|
|
|
|
>>> noble_gases = ElementMap(He='helium')
|
|
|
|
>>> noble_gases.element_for['He']
|
|
|
|
'helium'
|
|
|
|
>>> noble_gases.symbol_for['helium']
|
|
|
|
'He'
|
|
|
|
>>> noble_gases.element_for['Ne'] = 'neon'
|
|
|
|
>>> del noble_gases.symbol_for['helium']
|
|
|
|
>>> noble_gases
|
|
|
|
ElementMap({'Ne': 'neon'})
|
|
|
|
|
2015-12-25 19:13:02 +00:00
|
|
|
The *base_type* keyword arg,
|
2015-03-22 18:21:15 +00:00
|
|
|
whose default value is :class:`bidict.bidict`,
|
|
|
|
allows overriding the bidict type used as the base class,
|
2017-11-16 20:44:51 +00:00
|
|
|
allowing the creation of e.g. named frozen bidicts::
|
2015-03-22 18:21:15 +00:00
|
|
|
|
2017-11-20 03:24:08 +00:00
|
|
|
>>> from bidict import frozenbidict
|
|
|
|
>>> ElMap = namedbidict('ElMap', 'sym', 'el', base_type=frozenbidict)
|
2015-03-22 18:21:15 +00:00
|
|
|
>>> noble = ElMap(He='helium')
|
2016-06-28 04:05:22 +00:00
|
|
|
>>> hash(noble) is not 'an error'
|
2015-03-22 18:21:15 +00:00
|
|
|
True
|
|
|
|
>>> noble['C'] = 'carbon' # mutation fails
|
|
|
|
Traceback (most recent call last):
|
2015-12-21 03:05:20 +00:00
|
|
|
...
|
|
|
|
TypeError...
|