API¶
This page contains auto-generated documentation from the bidict source code.
bidict¶
The bidirectional mapping library for Python.
bidict by example:
>>> from bidict import bidict
>>> element_by_symbol = bidict({'H': 'hydrogen'})
>>> element_by_symbol['H']
'hydrogen'
>>> element_by_symbol.inverse['hydrogen']
'H'
Please see https://github.com/jab/bidict for the most up-to-date code and https://bidict.readthedocs.io for the most up-to-date documentation if you are reading this elsewhere.
-
class
bidict.
BidirectionalMapping
(*args, **kwds)¶ Bases:
collections.abc.Mapping
,typing.Generic
Abstract base class (ABC) for bidirectional mapping types.
Extends
collections.abc.Mapping
primarily by adding the (abstract)inverse
property, which implementors ofBidirectionalMapping
should override to return a reference to the inverseBidirectionalMapping
instance.-
__abstractmethods__
= frozenset({'__getitem__', '__iter__', '__len__', 'inverse'})¶
-
classmethod
__class_getitem__
(params)¶
-
__contains__
(key)¶
-
__eq__
(other)¶ Return self==value.
-
abstract
__getitem__
(key)¶
-
__hash__
= None¶
-
classmethod
__init_subclass__
(*args, **kwargs)¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__inverted__
()[source]¶ Get an iterator over the items in
inverse
.This is functionally equivalent to iterating over the items in the forward mapping and inverting each one on the fly, but this provides a more efficient implementation: Assuming the already-inverted items are stored in
inverse
, just return an iterator over them directly.Providing this default implementation enables external functions, particularly
inverted()
, to use this optimized implementation when available, instead of having to invert on the fly.See also
bidict.inverted()
-
abstract
__iter__
()¶
-
abstract
__len__
()¶
-
__module__
= 'bidict'¶
-
static
__new__
(cls, *args, **kwds)¶ Create and return a new object. See help(type) for accurate signature.
-
__orig_bases__
= (typing.Mapping[~KT, ~VT],)¶
-
__parameters__
= (~KT, ~VT)¶
-
__reversed__
= None¶
-
__slots__
= ()¶
-
classmethod
__subclasshook__
(C)¶ Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
-
_abc_impl
= <_abc_data object>¶
-
get
(k[, d]) → D[k] if k in D, else d. d defaults to None.¶
-
abstract property
inverse
¶ The inverse of this bidirectional mapping instance.
See also
bidict.BidictBase.inverse
,bidict.BidictBase.inv
- Raises
NotImplementedError – Meant to be overridden in subclasses.
- Return type
BidirectionalMapping
[~VT, ~KT]
-
items
() → a set-like object providing a view on D’s items¶
-
keys
() → a set-like object providing a view on D’s keys¶
-
values
()[source]¶ A set-like object providing a view on the contained values.
Override the implementation inherited from
Mapping
. Because the values of aBidirectionalMapping
are the keys of its inverse, this returns aKeysView
rather than aValuesView
, which has the advantages of constant-time containment checks and supporting set operations.- Return type
AbstractSet
[~VT]
-
-
class
bidict.
MutableBidirectionalMapping
(*args, **kwds)¶ Bases:
bidict.BidirectionalMapping
,collections.abc.MutableMapping
,typing.Generic
Abstract base class (ABC) for mutable bidirectional mapping types.
-
__abstractmethods__
= frozenset({'__delitem__', '__getitem__', '__iter__', '__len__', '__setitem__', 'inverse'})¶
-
classmethod
__class_getitem__
(params)¶
-
__contains__
(key)¶
-
abstract
__delitem__
(key)¶
-
__eq__
(other)¶ Return self==value.
-
abstract
__getitem__
(key)¶
-
__hash__
= None¶
-
classmethod
__init_subclass__
(*args, **kwargs)¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__inverted__
()¶ Get an iterator over the items in
inverse
.This is functionally equivalent to iterating over the items in the forward mapping and inverting each one on the fly, but this provides a more efficient implementation: Assuming the already-inverted items are stored in
inverse
, just return an iterator over them directly.Providing this default implementation enables external functions, particularly
inverted()
, to use this optimized implementation when available, instead of having to invert on the fly.See also
bidict.inverted()
-
abstract
__iter__
()¶
-
abstract
__len__
()¶
-
__module__
= 'bidict'¶
-
static
__new__
(cls, *args, **kwds)¶ Create and return a new object. See help(type) for accurate signature.
-
__orig_bases__
= (bidict.BidirectionalMapping[~KT, ~VT], typing.MutableMapping[~KT, ~VT])¶
-
__parameters__
= (~KT, ~VT)¶
-
__reversed__
= None¶
-
abstract
__setitem__
(key, value)¶
-
__slots__
= ()¶
-
classmethod
__subclasshook__
(C)¶ Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
-
_abc_impl
= <_abc_data object>¶
-
clear
() → None. Remove all items from D.¶
-
get
(k[, d]) → D[k] if k in D, else d. d defaults to None.¶
-
abstract property
inverse
¶ The inverse of this bidirectional mapping instance.
See also
bidict.BidictBase.inverse
,bidict.BidictBase.inv
- Raises
NotImplementedError – Meant to be overridden in subclasses.
- Return type
BidirectionalMapping
[~VT, ~KT]
-
items
() → a set-like object providing a view on D’s items¶
-
keys
() → a set-like object providing a view on D’s keys¶
-
pop
(k[, d]) → v, remove specified key and return the corresponding value.¶ If key is not found, d is returned if given, otherwise KeyError is raised.
-
popitem
() → (k, v), remove and return some (key, value) pair¶ as a 2-tuple; but raise KeyError if D is empty.
-
setdefault
(k[, d]) → D.get(k,d), also set D[k]=d if k not in D¶
-
update
([E, ]**F) → None. Update D from mapping/iterable E and F.¶ If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
-
values
()¶ A set-like object providing a view on the contained values.
Override the implementation inherited from
Mapping
. Because the values of aBidirectionalMapping
are the keys of its inverse, this returns aKeysView
rather than aValuesView
, which has the advantages of constant-time containment checks and supporting set operations.- Return type
AbstractSet
[~VT]
-
-
class
bidict.
BidictBase
(*args, **kw)¶ Bases:
bidict.BidirectionalMapping
Base class implementing
BidirectionalMapping
.-
_fwdm
¶
-
_invm
¶
-
_inv
¶
-
_invweak
¶
-
_hash
¶
-
__abstractmethods__
= frozenset({})¶
-
classmethod
__class_getitem__
(params)¶
-
__contains__
(key)¶
-
__copy__
()¶ A shallow copy.
- Return type
~BT
-
__eq__
(other)[source]¶ x.__eq__(other) ⟺ x == other
Equivalent to dict(x.items()) == dict(other.items()) but more efficient.
Note that
bidict's __eq__()
implementation is inherited by subclasses, in particular by the ordered bidict subclasses, so even with ordered bidicts, == comparison is order-insensitive.See also
bidict.FrozenOrderedBidict.equals_order_sensitive()
- Return type
-
__getstate__
()[source]¶ Needed to enable pickling due to use of
__slots__
and weakrefs.See also
object.__getstate__()
- Return type
-
__hash__
= None¶
-
__init__
(*args, **kw)[source]¶ Make a new bidirectional dictionary. The signature behaves like that of
dict
. Items passed in are added in the order they are passed, respecting theon_dup
class attribute in the process.
-
classmethod
__init_subclass__
(**kw)[source]¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__inverted__
()¶ Get an iterator over the items in
inverse
.This is functionally equivalent to iterating over the items in the forward mapping and inverting each one on the fly, but this provides a more efficient implementation: Assuming the already-inverted items are stored in
inverse
, just return an iterator over them directly.Providing this default implementation enables external functions, particularly
inverted()
, to use this optimized implementation when available, instead of having to invert on the fly.See also
bidict.inverted()
-
__module__
= 'bidict'¶
-
static
__new__
(cls, *args, **kwds)¶ Create and return a new object. See help(type) for accurate signature.
-
__orig_bases__
= (bidict.BidirectionalMapping[~KT, ~VT],)¶
-
__parameters__
= (~KT, ~VT)¶
-
__reversed__
= None¶
-
__setstate__
(state)[source]¶ Implemented because use of
__slots__
would prevent unpickling otherwise.See also
object.__setstate__()
- Return type
None
-
__slots__
= ['_fwdm', '_invm', '_inv', '_invweak', '_hash']¶
-
classmethod
__subclasshook__
(C)¶ Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
-
__weakref__
¶ list of weak references to the object (if defined)
-
_abc_impl
= <_abc_data object>¶
-
_dedup_item
(key, val, on_dup)[source]¶ Check key and val for any duplication in self.
Handle any duplication as per the passed in on_dup.
(key, val) already present is construed as a no-op, not a duplication.
If duplication is found and the corresponding
OnDupAction
isDROP_NEW
, return None.If duplication is found and the corresponding
OnDupAction
isRAISE
, raise the appropriate error.If duplication is found and the corresponding
OnDupAction
isDROP_OLD
, or if no duplication is found, return the_DedupResult
(isdupkey, isdupval, oldkey, oldval).- Return type
Optional
[_DedupResult
]
-
_fwdm_cls
¶ alias of
builtins.dict
-
_invm_cls
¶ alias of
builtins.dict
-
_repr_delegate
¶ alias of
builtins.dict
-
_update_with_rollback
(on_dup, *args, **kw)[source]¶ Update, rolling back on failure.
- Return type
None
-
get
(k[, d]) → D[k] if k in D, else d. d defaults to None.¶
-
property
inv
¶ The inverse of this bidict.
- Return type
BidictBase
[~VT, ~KT]
-
property
inverse
¶ The inverse of this bidict.
- Return type
BidictBase
[~VT, ~KT]
-
items
() → a set-like object providing a view on D’s items¶
-
keys
() → a set-like object providing a view on D’s keys¶
-
on_dup
= OnDup(key=<DROP_OLD>, val=<RAISE>, kv=<RAISE>)¶
-
values
()¶ A set-like object providing a view on the contained values.
Override the implementation inherited from
Mapping
. Because the values of aBidirectionalMapping
are the keys of its inverse, this returns aKeysView
rather than aValuesView
, which has the advantages of constant-time containment checks and supporting set operations.- Return type
AbstractSet
[~VT]
-
-
class
bidict.
MutableBidict
(*args, **kw)¶ Bases:
bidict.BidictBase
,bidict.MutableBidirectionalMapping
Base class for mutable bidirectional mappings.
-
__abstractmethods__
= frozenset({})¶
-
classmethod
__class_getitem__
(params)¶
-
__contains__
(key)¶
-
__copy__
()¶ A shallow copy.
- Return type
~BT
-
__eq__
(other)¶ x.__eq__(other) ⟺ x == other
Equivalent to dict(x.items()) == dict(other.items()) but more efficient.
Note that
bidict's __eq__()
implementation is inherited by subclasses, in particular by the ordered bidict subclasses, so even with ordered bidicts, == comparison is order-insensitive.See also
bidict.FrozenOrderedBidict.equals_order_sensitive()
- Return type
-
__getitem__
(key)¶ x.__getitem__(key) ⟺ x[key]
- Return type
~VT
-
__getstate__
()¶ Needed to enable pickling due to use of
__slots__
and weakrefs.See also
object.__getstate__()
- Return type
-
__hash__
= None¶
-
__init__
(*args, **kw)¶ Make a new bidirectional dictionary. The signature behaves like that of
dict
. Items passed in are added in the order they are passed, respecting theon_dup
class attribute in the process.
-
classmethod
__init_subclass__
(**kw)¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__inverted__
()¶ Get an iterator over the items in
inverse
.This is functionally equivalent to iterating over the items in the forward mapping and inverting each one on the fly, but this provides a more efficient implementation: Assuming the already-inverted items are stored in
inverse
, just return an iterator over them directly.Providing this default implementation enables external functions, particularly
inverted()
, to use this optimized implementation when available, instead of having to invert on the fly.See also
bidict.inverted()
-
__module__
= 'bidict'¶
-
static
__new__
(cls, *args, **kwds)¶ Create and return a new object. See help(type) for accurate signature.
-
__orig_bases__
= (bidict.BidictBase[~KT, ~VT], bidict.MutableBidirectionalMapping[~KT, ~VT])¶
-
__parameters__
= (~KT, ~VT)¶
-
__reversed__
= None¶
-
__setitem__
(key, val)[source]¶ Set the value for key to val.
If key is already associated with val, this is a no-op.
If key is already associated with a different value, the old value will be replaced with val, as with dict’s
__setitem__()
.If val is already associated with a different key, an exception is raised to protect against accidental removal of the key that’s currently associated with val.
Use
put()
instead if you want to specify different behavior in the case that the provided key or value duplicates an existing one. Or useforceput()
to unconditionally associate key with val, replacing any existing items as necessary to preserve uniqueness.- Raises
bidict.ValueDuplicationError – if val duplicates that of an existing item.
bidict.KeyAndValueDuplicationError – if key duplicates the key of an existing item and val duplicates the value of a different existing item.
- Return type
None
-
__setstate__
(state)¶ Implemented because use of
__slots__
would prevent unpickling otherwise.See also
object.__setstate__()
- Return type
None
-
__slots__
= ()¶
-
classmethod
__subclasshook__
(C)¶ Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
-
__weakref__
¶ list of weak references to the object (if defined)
-
_abc_impl
= <_abc_data object>¶
-
_dedup_item
(key, val, on_dup)¶ Check key and val for any duplication in self.
Handle any duplication as per the passed in on_dup.
(key, val) already present is construed as a no-op, not a duplication.
If duplication is found and the corresponding
OnDupAction
isDROP_NEW
, return None.If duplication is found and the corresponding
OnDupAction
isRAISE
, raise the appropriate error.If duplication is found and the corresponding
OnDupAction
isDROP_OLD
, or if no duplication is found, return the_DedupResult
(isdupkey, isdupval, oldkey, oldval).- Return type
Optional
[_DedupResult
]
-
_fwdm
¶
-
_fwdm_cls
¶ alias of
builtins.dict
-
_hash
¶
-
_init_inv
()¶ - Return type
None
-
_inv
¶
-
_inv_cls
¶ alias of
MutableBidict
-
_invm
¶
-
_invm_cls
¶ alias of
builtins.dict
-
_invweak
¶
-
_pop
(key)¶ - Return type
~VT
-
_put
(key, val, on_dup)¶ - Return type
None
-
_repr_delegate
¶ alias of
builtins.dict
-
_undo_write
(dedup_result, write_result)¶ - Return type
None
-
_update
(init, on_dup, *args, **kw)¶ - Return type
None
-
_update_no_dup_check
(other)¶ - Return type
None
-
_update_no_rollback
(on_dup, *args, **kw)¶ - Return type
None
-
_update_with_rollback
(on_dup, *args, **kw)¶ Update, rolling back on failure.
- Return type
None
-
_write_item
(key, val, dedup_result)¶ - Return type
_WriteResult
-
copy
()¶ A shallow copy.
- Return type
~BT
-
forceput
(key, val)[source]¶ Associate key with val unconditionally.
Replace any existing mappings containing key key or value val as necessary to preserve uniqueness.
- Return type
None
-
forceupdate
(*args, **kw)[source]¶ Like a bulk
forceput()
.- Return type
None
-
get
(k[, d]) → D[k] if k in D, else d. d defaults to None.¶
-
property
inv
¶ The inverse of this bidict.
- Return type
BidictBase
[~VT, ~KT]
-
property
inverse
¶ The inverse of this bidict.
- Return type
BidictBase
[~VT, ~KT]
-
items
() → a set-like object providing a view on D’s items¶
-
keys
() → a set-like object providing a view on D’s keys¶
-
on_dup
= OnDup(key=<DROP_OLD>, val=<RAISE>, kv=<RAISE>)¶
-
pop
(key, default=<_NONE>)[source]¶ x.pop(k[, d]) → v
Remove specified key and return the corresponding value.
-
put
(key, val, on_dup=OnDup(key=<RAISE>, val=<RAISE>, kv=<RAISE>))[source]¶ Associate key with val, honoring the
OnDup
given in on_dup.For example, if on_dup is
ON_DUP_RAISE
, then key will be associated with val if and only if key is not already associated with an existing value and val is not already associated with an existing key, otherwise an exception will be raised.If key is already associated with val, this is a no-op.
- Raises
bidict.KeyDuplicationError – if attempting to insert an item whose key only duplicates an existing item’s, and on_dup.key is
RAISE
.bidict.ValueDuplicationError – if attempting to insert an item whose value only duplicates an existing item’s, and on_dup.val is
RAISE
.bidict.KeyAndValueDuplicationError – if attempting to insert an item whose key duplicates one existing item’s, and whose value duplicates another existing item’s, and on_dup.kv is
RAISE
.
- Return type
None
-
putall
(items, on_dup=OnDup(key=<RAISE>, val=<RAISE>, kv=<RAISE>))[source]¶ Like a bulk
put()
.If one of the given items causes an exception to be raised, none of the items is inserted.
- Return type
None
-
setdefault
(k[, d]) → D.get(k,d), also set D[k]=d if k not in D¶
-
update
(*args, **kw)[source]¶ Like calling
putall()
with self.on_dup passed for on_dup.- Return type
None
-
values
()¶ A set-like object providing a view on the contained values.
Override the implementation inherited from
Mapping
. Because the values of aBidirectionalMapping
are the keys of its inverse, this returns aKeysView
rather than aValuesView
, which has the advantages of constant-time containment checks and supporting set operations.- Return type
AbstractSet
[~VT]
-
-
class
bidict.
bidict
(*args, **kw)¶ Bases:
bidict._delegating._DelegatingBidict
,bidict.MutableBidict
Base class for mutable bidirectional mappings.
-
__abstractmethods__
= frozenset({})¶
-
classmethod
__class_getitem__
(params)¶
-
__contains__
(key)¶
-
__copy__
()¶ A shallow copy.
- Return type
~BT
-
__delitem__
(key)¶ x.__delitem__(y) ⟺ del x[y]
- Return type
None
-
__eq__
(other)¶ x.__eq__(other) ⟺ x == other
Equivalent to dict(x.items()) == dict(other.items()) but more efficient.
Note that
bidict's __eq__()
implementation is inherited by subclasses, in particular by the ordered bidict subclasses, so even with ordered bidicts, == comparison is order-insensitive.See also
bidict.FrozenOrderedBidict.equals_order_sensitive()
- Return type
-
__getitem__
(key)¶ x.__getitem__(key) ⟺ x[key]
- Return type
~VT
-
__getstate__
()¶ Needed to enable pickling due to use of
__slots__
and weakrefs.See also
object.__getstate__()
- Return type
-
__hash__
= None¶
-
__init__
(*args, **kw)¶ Make a new bidirectional dictionary. The signature behaves like that of
dict
. Items passed in are added in the order they are passed, respecting theon_dup
class attribute in the process.
-
classmethod
__init_subclass__
(**kw)¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__inverted__
()¶ Get an iterator over the items in
inverse
.This is functionally equivalent to iterating over the items in the forward mapping and inverting each one on the fly, but this provides a more efficient implementation: Assuming the already-inverted items are stored in
inverse
, just return an iterator over them directly.Providing this default implementation enables external functions, particularly
inverted()
, to use this optimized implementation when available, instead of having to invert on the fly.See also
bidict.inverted()
-
__module__
= 'bidict'¶
-
static
__new__
(cls, *args, **kwds)¶ Create and return a new object. See help(type) for accurate signature.
-
__orig_bases__
= (bidict._delegating._DelegatingBidict[~KT, ~VT], bidict.MutableBidict[~KT, ~VT])¶
-
__parameters__
= (~KT, ~VT)¶
-
__reversed__
= None¶
-
__setitem__
(key, val)¶ Set the value for key to val.
If key is already associated with val, this is a no-op.
If key is already associated with a different value, the old value will be replaced with val, as with dict’s
__setitem__()
.If val is already associated with a different key, an exception is raised to protect against accidental removal of the key that’s currently associated with val.
Use
put()
instead if you want to specify different behavior in the case that the provided key or value duplicates an existing one. Or useforceput()
to unconditionally associate key with val, replacing any existing items as necessary to preserve uniqueness.- Raises
bidict.ValueDuplicationError – if val duplicates that of an existing item.
bidict.KeyAndValueDuplicationError – if key duplicates the key of an existing item and val duplicates the value of a different existing item.
- Return type
None
-
__setstate__
(state)¶ Implemented because use of
__slots__
would prevent unpickling otherwise.See also
object.__setstate__()
- Return type
None
-
__slots__
= ()¶
-
classmethod
__subclasshook__
(C)¶ Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
-
__weakref__
¶ list of weak references to the object (if defined)
-
_abc_impl
= <_abc_data object>¶
-
_dedup_item
(key, val, on_dup)¶ Check key and val for any duplication in self.
Handle any duplication as per the passed in on_dup.
(key, val) already present is construed as a no-op, not a duplication.
If duplication is found and the corresponding
OnDupAction
isDROP_NEW
, return None.If duplication is found and the corresponding
OnDupAction
isRAISE
, raise the appropriate error.If duplication is found and the corresponding
OnDupAction
isDROP_OLD
, or if no duplication is found, return the_DedupResult
(isdupkey, isdupval, oldkey, oldval).- Return type
Optional
[_DedupResult
]
-
_fwdm
¶
-
_fwdm_cls
¶ alias of
builtins.dict
-
_hash
¶
-
_init_inv
()¶ - Return type
None
-
_inv
¶
-
_invm
¶
-
_invm_cls
¶ alias of
builtins.dict
-
_invweak
¶
-
_pop
(key)¶ - Return type
~VT
-
_put
(key, val, on_dup)¶ - Return type
None
-
_repr_delegate
¶ alias of
builtins.dict
-
_undo_write
(dedup_result, write_result)¶ - Return type
None
-
_update
(init, on_dup, *args, **kw)¶ - Return type
None
-
_update_no_dup_check
(other)¶ - Return type
None
-
_update_no_rollback
(on_dup, *args, **kw)¶ - Return type
None
-
_update_with_rollback
(on_dup, *args, **kw)¶ Update, rolling back on failure.
- Return type
None
-
_write_item
(key, val, dedup_result)¶ - Return type
_WriteResult
-
clear
()¶ Remove all items.
- Return type
None
-
copy
()¶ A shallow copy.
- Return type
~BT
-
forceput
(key, val)¶ Associate key with val unconditionally.
Replace any existing mappings containing key key or value val as necessary to preserve uniqueness.
- Return type
None
-
forceupdate
(*args, **kw)¶ Like a bulk
forceput()
.- Return type
None
-
get
(k[, d]) → D[k] if k in D, else d. d defaults to None.¶
-
property
inv
¶ The inverse of this bidict.
- Return type
BidictBase
[~VT, ~KT]
-
property
inverse
¶ The inverse of this bidict.
- Return type
BidictBase
[~VT, ~KT]
-
on_dup
= OnDup(key=<DROP_OLD>, val=<RAISE>, kv=<RAISE>)¶
-
pop
(key, default=<_NONE>)¶ x.pop(k[, d]) → v
Remove specified key and return the corresponding value.
-
popitem
()¶ x.popitem() → (k, v)
Remove and return some item as a (key, value) pair.
-
put
(key, val, on_dup=OnDup(key=<RAISE>, val=<RAISE>, kv=<RAISE>))¶ Associate key with val, honoring the
OnDup
given in on_dup.For example, if on_dup is
ON_DUP_RAISE
, then key will be associated with val if and only if key is not already associated with an existing value and val is not already associated with an existing key, otherwise an exception will be raised.If key is already associated with val, this is a no-op.
- Raises
bidict.KeyDuplicationError – if attempting to insert an item whose key only duplicates an existing item’s, and on_dup.key is
RAISE
.bidict.ValueDuplicationError – if attempting to insert an item whose value only duplicates an existing item’s, and on_dup.val is
RAISE
.bidict.KeyAndValueDuplicationError – if attempting to insert an item whose key duplicates one existing item’s, and whose value duplicates another existing item’s, and on_dup.kv is
RAISE
.
- Return type
None
-
putall
(items, on_dup=OnDup(key=<RAISE>, val=<RAISE>, kv=<RAISE>))¶ Like a bulk
put()
.If one of the given items causes an exception to be raised, none of the items is inserted.
- Return type
None
-
setdefault
(k[, d]) → D.get(k,d), also set D[k]=d if k not in D¶
-
-
class
bidict.
frozenbidict
(*args, **kw)¶ Bases:
bidict._delegating._DelegatingBidict
Immutable, hashable bidict type.
-
__abstractmethods__
= frozenset({})¶
-
classmethod
__class_getitem__
(params)¶
-
__contains__
(key)¶
-
__copy__
()¶ A shallow copy.
- Return type
~BT
-
__eq__
(other)¶ x.__eq__(other) ⟺ x == other
Equivalent to dict(x.items()) == dict(other.items()) but more efficient.
Note that
bidict's __eq__()
implementation is inherited by subclasses, in particular by the ordered bidict subclasses, so even with ordered bidicts, == comparison is order-insensitive.See also
bidict.FrozenOrderedBidict.equals_order_sensitive()
- Return type
-
__getitem__
(key)¶ x.__getitem__(key) ⟺ x[key]
- Return type
~VT
-
__getstate__
()¶ Needed to enable pickling due to use of
__slots__
and weakrefs.See also
object.__getstate__()
- Return type
-
__init__
(*args, **kw)¶ Make a new bidirectional dictionary. The signature behaves like that of
dict
. Items passed in are added in the order they are passed, respecting theon_dup
class attribute in the process.
-
classmethod
__init_subclass__
(**kw)¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__inverted__
()¶ Get an iterator over the items in
inverse
.This is functionally equivalent to iterating over the items in the forward mapping and inverting each one on the fly, but this provides a more efficient implementation: Assuming the already-inverted items are stored in
inverse
, just return an iterator over them directly.Providing this default implementation enables external functions, particularly
inverted()
, to use this optimized implementation when available, instead of having to invert on the fly.See also
bidict.inverted()
-
__module__
= 'bidict'¶
-
static
__new__
(cls, *args, **kwds)¶ Create and return a new object. See help(type) for accurate signature.
-
__orig_bases__
= (bidict._delegating._DelegatingBidict[~KT, ~VT],)¶
-
__parameters__
= (~KT, ~VT)¶
-
__reversed__
= None¶
-
__setstate__
(state)¶ Implemented because use of
__slots__
would prevent unpickling otherwise.See also
object.__setstate__()
- Return type
None
-
__slots__
= ()¶
-
classmethod
__subclasshook__
(C)¶ Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
-
__weakref__
¶ list of weak references to the object (if defined)
-
_abc_impl
= <_abc_data object>¶
-
_dedup_item
(key, val, on_dup)¶ Check key and val for any duplication in self.
Handle any duplication as per the passed in on_dup.
(key, val) already present is construed as a no-op, not a duplication.
If duplication is found and the corresponding
OnDupAction
isDROP_NEW
, return None.If duplication is found and the corresponding
OnDupAction
isRAISE
, raise the appropriate error.If duplication is found and the corresponding
OnDupAction
isDROP_OLD
, or if no duplication is found, return the_DedupResult
(isdupkey, isdupval, oldkey, oldval).- Return type
Optional
[_DedupResult
]
-
_fwdm
¶
-
_fwdm_cls
¶ alias of
builtins.dict
-
_hash
¶
-
_init_inv
()¶ - Return type
None
-
_inv
¶
-
_inv_cls
¶ alias of
frozenbidict
-
_invm
¶
-
_invm_cls
¶ alias of
builtins.dict
-
_invweak
¶
-
_pop
(key)¶ - Return type
~VT
-
_put
(key, val, on_dup)¶ - Return type
None
-
_repr_delegate
¶ alias of
builtins.dict
-
_undo_write
(dedup_result, write_result)¶ - Return type
None
-
_update
(init, on_dup, *args, **kw)¶ - Return type
None
-
_update_no_dup_check
(other)¶ - Return type
None
-
_update_no_rollback
(on_dup, *args, **kw)¶ - Return type
None
-
_update_with_rollback
(on_dup, *args, **kw)¶ Update, rolling back on failure.
- Return type
None
-
_write_item
(key, val, dedup_result)¶ - Return type
_WriteResult
-
copy
()¶ A shallow copy.
- Return type
~BT
-
get
(k[, d]) → D[k] if k in D, else d. d defaults to None.¶
-
property
inv
¶ The inverse of this bidict.
- Return type
BidictBase
[~VT, ~KT]
-
property
inverse
¶ The inverse of this bidict.
- Return type
BidictBase
[~VT, ~KT]
-
on_dup
= OnDup(key=<DROP_OLD>, val=<RAISE>, kv=<RAISE>)¶
-
-
class
bidict.
FrozenOrderedBidict
(*args, **kw)¶ Bases:
bidict.OrderedBidictBase
Hashable, immutable, ordered bidict type.
-
__abstractmethods__
= frozenset({})¶
-
__annotations__
= {}¶
-
classmethod
__class_getitem__
(params)¶
-
__contains__
(key)¶
-
__copy__
()¶ A shallow copy of this ordered bidict.
- Return type
~BT
-
__eq__
(other)¶ x.__eq__(other) ⟺ x == other
Equivalent to dict(x.items()) == dict(other.items()) but more efficient.
Note that
bidict's __eq__()
implementation is inherited by subclasses, in particular by the ordered bidict subclasses, so even with ordered bidicts, == comparison is order-insensitive.See also
bidict.FrozenOrderedBidict.equals_order_sensitive()
- Return type
-
__getitem__
(key)¶ x.__getitem__(key) ⟺ x[key]
- Return type
~VT
-
__getstate__
()¶ Needed to enable pickling due to use of
__slots__
and weakrefs.See also
object.__getstate__()
- Return type
-
__init__
(*args, **kw)¶ Make a new ordered bidirectional mapping. The signature behaves like that of
dict
. Items passed in are added in the order they are passed, respecting theon_dup
class attribute in the process.The order in which items are inserted is remembered, similar to
collections.OrderedDict
.
-
classmethod
__init_subclass__
(**kw)¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__inverted__
()¶ Get an iterator over the items in
inverse
.This is functionally equivalent to iterating over the items in the forward mapping and inverting each one on the fly, but this provides a more efficient implementation: Assuming the already-inverted items are stored in
inverse
, just return an iterator over them directly.Providing this default implementation enables external functions, particularly
inverted()
, to use this optimized implementation when available, instead of having to invert on the fly.See also
bidict.inverted()
-
__module__
= 'bidict'¶
-
static
__new__
(cls, *args, **kwds)¶ Create and return a new object. See help(type) for accurate signature.
-
__orig_bases__
= (bidict.OrderedBidictBase[~KT, ~VT],)¶
-
__parameters__
= (~KT, ~VT)¶
-
__reversed__
()¶ Iterator over the contained keys in reverse insertion order.
- Return type
Iterator
[~KT]
-
__setstate__
(state)¶ Implemented because use of
__slots__
would prevent unpickling otherwise.See also
object.__setstate__()
- Return type
None
-
__slots__
= ()¶
-
classmethod
__subclasshook__
(C)¶ Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
-
__weakref__
¶ list of weak references to the object (if defined)
-
_abc_impl
= <_abc_data object>¶
-
_dedup_item
(key, val, on_dup)¶ Check key and val for any duplication in self.
Handle any duplication as per the passed in on_dup.
(key, val) already present is construed as a no-op, not a duplication.
If duplication is found and the corresponding
OnDupAction
isDROP_NEW
, return None.If duplication is found and the corresponding
OnDupAction
isRAISE
, raise the appropriate error.If duplication is found and the corresponding
OnDupAction
isDROP_OLD
, or if no duplication is found, return the_DedupResult
(isdupkey, isdupval, oldkey, oldval).- Return type
Optional
[_DedupResult
]
-
_fwdm
¶
-
_hash
¶
-
_init_inv
()¶ - Return type
None
-
_inv
¶
-
_inv_cls
¶ alias of
FrozenOrderedBidict
-
_invm
¶
-
_invweak
¶
-
_pop
(key)¶ - Return type
~VT
-
_put
(key, val, on_dup)¶ - Return type
None
-
_repr_delegate
¶ alias of
builtins.list
-
_sntl
¶
-
_undo_write
(dedup_result, write_result)¶ - Return type
None
-
_update
(init, on_dup, *args, **kw)¶ - Return type
None
-
_update_no_dup_check
(other)¶ - Return type
None
-
_update_no_rollback
(on_dup, *args, **kw)¶ - Return type
None
-
_update_with_rollback
(on_dup, *args, **kw)¶ Update, rolling back on failure.
- Return type
None
-
_write_item
(key, val, dedup_result)¶ - Return type
_WriteResult
-
copy
()¶ A shallow copy of this ordered bidict.
- Return type
~BT
-
equals_order_sensitive
(other)¶ Order-sensitive equality check.
See also __eq__() is order-insensitive
- Return type
-
get
(k[, d]) → D[k] if k in D, else d. d defaults to None.¶
-
property
inv
¶ The inverse of this bidict.
- Return type
BidictBase
[~VT, ~KT]
-
property
inverse
¶ The inverse of this bidict.
- Return type
BidictBase
[~VT, ~KT]
-
items
() → a set-like object providing a view on D’s items¶
-
on_dup
= OnDup(key=<DROP_OLD>, val=<RAISE>, kv=<RAISE>)¶
-
-
bidict.
namedbidict
(typename, keyname, valname, *, base_type=<class 'bidict.bidict'>)¶ Create a new subclass of base_type with custom accessors.
Like
collections.namedtuple()
for bidicts.The new class’s
__name__
and__qualname__
will be set to typename, and its__module__
will be set to the caller’s module.Instances of the new class will provide access to their
inverse
instances via the custom keyname_for property, and access to themselves via the custom valname_for property.See also the namedbidict usage documentation
- Raises
ValueError – if any of the typename, keyname, or valname strings is not a valid Python identifier, or if keyname == valname.
TypeError – if base_type is not a
BidirectionalMapping
subclass that provides_isinv
and__getstate__()
attributes. (AnyBidictBase
subclass can be passed in, including all the concrete bidict types pictured in the Bidict Types Diagram.
- Return type
Type
[BidirectionalMapping
[~KT, ~VT]]
-
class
bidict.
OrderedBidictBase
(*args, **kw)¶ Bases:
bidict.BidictBase
Base class implementing an ordered
BidirectionalMapping
.-
_sntl
¶
-
__abstractmethods__
= frozenset({})¶
-
__annotations__
= {}¶
-
classmethod
__class_getitem__
(params)¶
-
__contains__
(key)¶
-
__copy__
()¶ A shallow copy of this ordered bidict.
- Return type
~BT
-
__eq__
(other)¶ x.__eq__(other) ⟺ x == other
Equivalent to dict(x.items()) == dict(other.items()) but more efficient.
Note that
bidict's __eq__()
implementation is inherited by subclasses, in particular by the ordered bidict subclasses, so even with ordered bidicts, == comparison is order-insensitive.See also
bidict.FrozenOrderedBidict.equals_order_sensitive()
- Return type
-
__getstate__
()¶ Needed to enable pickling due to use of
__slots__
and weakrefs.See also
object.__getstate__()
- Return type
-
__hash__
= None¶
-
__init__
(*args, **kw)[source]¶ Make a new ordered bidirectional mapping. The signature behaves like that of
dict
. Items passed in are added in the order they are passed, respecting theon_dup
class attribute in the process.The order in which items are inserted is remembered, similar to
collections.OrderedDict
.
-
classmethod
__init_subclass__
(**kw)¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__inverted__
()¶ Get an iterator over the items in
inverse
.This is functionally equivalent to iterating over the items in the forward mapping and inverting each one on the fly, but this provides a more efficient implementation: Assuming the already-inverted items are stored in
inverse
, just return an iterator over them directly.Providing this default implementation enables external functions, particularly
inverted()
, to use this optimized implementation when available, instead of having to invert on the fly.See also
bidict.inverted()
-
__module__
= 'bidict'¶
-
static
__new__
(cls, *args, **kwds)¶ Create and return a new object. See help(type) for accurate signature.
-
__orig_bases__
= (bidict.BidictBase[~KT, ~VT],)¶
-
__parameters__
= (~KT, ~VT)¶
-
__reversed__
()[source]¶ Iterator over the contained keys in reverse insertion order.
- Return type
Iterator
[~KT]
-
__setstate__
(state)¶ Implemented because use of
__slots__
would prevent unpickling otherwise.See also
object.__setstate__()
- Return type
None
-
__slots__
= ('_sntl',)¶
-
classmethod
__subclasshook__
(C)¶ Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
-
__weakref__
¶ list of weak references to the object (if defined)
-
_abc_impl
= <_abc_data object>¶
-
_dedup_item
(key, val, on_dup)¶ Check key and val for any duplication in self.
Handle any duplication as per the passed in on_dup.
(key, val) already present is construed as a no-op, not a duplication.
If duplication is found and the corresponding
OnDupAction
isDROP_NEW
, return None.If duplication is found and the corresponding
OnDupAction
isRAISE
, raise the appropriate error.If duplication is found and the corresponding
OnDupAction
isDROP_OLD
, or if no duplication is found, return the_DedupResult
(isdupkey, isdupval, oldkey, oldval).- Return type
Optional
[_DedupResult
]
-
_fwdm
¶
-
_hash
¶
-
_inv
¶
-
_inv_cls
¶ alias of
OrderedBidictBase
-
_invm
¶
-
_invweak
¶
-
_put
(key, val, on_dup)¶ - Return type
None
-
_repr_delegate
¶ alias of
builtins.list
-
_update
(init, on_dup, *args, **kw)¶ - Return type
None
-
_update_no_dup_check
(other)¶ - Return type
None
-
_update_no_rollback
(on_dup, *args, **kw)¶ - Return type
None
-
_update_with_rollback
(on_dup, *args, **kw)¶ Update, rolling back on failure.
- Return type
None
-
equals_order_sensitive
(other)[source]¶ Order-sensitive equality check.
See also __eq__() is order-insensitive
- Return type
-
get
(k[, d]) → D[k] if k in D, else d. d defaults to None.¶
-
property
inv
¶ The inverse of this bidict.
- Return type
BidictBase
[~VT, ~KT]
-
property
inverse
¶ The inverse of this bidict.
- Return type
BidictBase
[~VT, ~KT]
-
items
() → a set-like object providing a view on D’s items¶
-
keys
() → a set-like object providing a view on D’s keys¶
-
on_dup
= OnDup(key=<DROP_OLD>, val=<RAISE>, kv=<RAISE>)¶
-
values
()¶ A set-like object providing a view on the contained values.
Override the implementation inherited from
Mapping
. Because the values of aBidirectionalMapping
are the keys of its inverse, this returns aKeysView
rather than aValuesView
, which has the advantages of constant-time containment checks and supporting set operations.- Return type
AbstractSet
[~VT]
-
-
class
bidict.
OrderedBidict
(*args, **kw)¶ Bases:
bidict.OrderedBidictBase
,bidict.MutableBidict
Mutable bidict type that maintains items in insertion order.
-
__abstractmethods__
= frozenset({})¶
-
__annotations__
= {}¶
-
classmethod
__class_getitem__
(params)¶
-
__contains__
(key)¶
-
__copy__
()¶ A shallow copy of this ordered bidict.
- Return type
~BT
-
__delitem__
(key)¶ x.__delitem__(y) ⟺ del x[y]
- Return type
None
-
__eq__
(other)¶ x.__eq__(other) ⟺ x == other
Equivalent to dict(x.items()) == dict(other.items()) but more efficient.
Note that
bidict's __eq__()
implementation is inherited by subclasses, in particular by the ordered bidict subclasses, so even with ordered bidicts, == comparison is order-insensitive.See also
bidict.FrozenOrderedBidict.equals_order_sensitive()
- Return type
-
__getitem__
(key)¶ x.__getitem__(key) ⟺ x[key]
- Return type
~VT
-
__getstate__
()¶ Needed to enable pickling due to use of
__slots__
and weakrefs.See also
object.__getstate__()
- Return type
-
__hash__
= None¶
-
__init__
(*args, **kw)¶ Make a new ordered bidirectional mapping. The signature behaves like that of
dict
. Items passed in are added in the order they are passed, respecting theon_dup
class attribute in the process.The order in which items are inserted is remembered, similar to
collections.OrderedDict
.
-
classmethod
__init_subclass__
(**kw)¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__inverted__
()¶ Get an iterator over the items in
inverse
.This is functionally equivalent to iterating over the items in the forward mapping and inverting each one on the fly, but this provides a more efficient implementation: Assuming the already-inverted items are stored in
inverse
, just return an iterator over them directly.Providing this default implementation enables external functions, particularly
inverted()
, to use this optimized implementation when available, instead of having to invert on the fly.See also
bidict.inverted()
-
__module__
= 'bidict'¶
-
static
__new__
(cls, *args, **kwds)¶ Create and return a new object. See help(type) for accurate signature.
-
__orig_bases__
= (bidict.OrderedBidictBase[~KT, ~VT], bidict.MutableBidict[~KT, ~VT])¶
-
__parameters__
= (~KT, ~VT)¶
-
__reversed__
()¶ Iterator over the contained keys in reverse insertion order.
- Return type
Iterator
[~KT]
-
__setitem__
(key, val)¶ Set the value for key to val.
If key is already associated with val, this is a no-op.
If key is already associated with a different value, the old value will be replaced with val, as with dict’s
__setitem__()
.If val is already associated with a different key, an exception is raised to protect against accidental removal of the key that’s currently associated with val.
Use
put()
instead if you want to specify different behavior in the case that the provided key or value duplicates an existing one. Or useforceput()
to unconditionally associate key with val, replacing any existing items as necessary to preserve uniqueness.- Raises
bidict.ValueDuplicationError – if val duplicates that of an existing item.
bidict.KeyAndValueDuplicationError – if key duplicates the key of an existing item and val duplicates the value of a different existing item.
- Return type
None
-
__setstate__
(state)¶ Implemented because use of
__slots__
would prevent unpickling otherwise.See also
object.__setstate__()
- Return type
None
-
__slots__
= ()¶
-
classmethod
__subclasshook__
(C)¶ Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
-
__weakref__
¶ list of weak references to the object (if defined)
-
_abc_impl
= <_abc_data object>¶
-
_dedup_item
(key, val, on_dup)¶ Check key and val for any duplication in self.
Handle any duplication as per the passed in on_dup.
(key, val) already present is construed as a no-op, not a duplication.
If duplication is found and the corresponding
OnDupAction
isDROP_NEW
, return None.If duplication is found and the corresponding
OnDupAction
isRAISE
, raise the appropriate error.If duplication is found and the corresponding
OnDupAction
isDROP_OLD
, or if no duplication is found, return the_DedupResult
(isdupkey, isdupval, oldkey, oldval).- Return type
Optional
[_DedupResult
]
-
_fwdm
¶
-
_hash
¶
-
_init_inv
()¶ - Return type
None
-
_inv
¶
-
_inv_cls
¶ alias of
OrderedBidict
-
_invm
¶
-
_invweak
¶
-
_pop
(key)¶ - Return type
~VT
-
_put
(key, val, on_dup)¶ - Return type
None
-
_repr_delegate
¶ alias of
builtins.list
-
_sntl
¶
-
_undo_write
(dedup_result, write_result)¶ - Return type
None
-
_update
(init, on_dup, *args, **kw)¶ - Return type
None
-
_update_no_dup_check
(other)¶ - Return type
None
-
_update_no_rollback
(on_dup, *args, **kw)¶ - Return type
None
-
_update_with_rollback
(on_dup, *args, **kw)¶ Update, rolling back on failure.
- Return type
None
-
_write_item
(key, val, dedup_result)¶ - Return type
_WriteResult
-
copy
()¶ A shallow copy of this ordered bidict.
- Return type
~BT
-
equals_order_sensitive
(other)¶ Order-sensitive equality check.
See also __eq__() is order-insensitive
- Return type
-
forceput
(key, val)¶ Associate key with val unconditionally.
Replace any existing mappings containing key key or value val as necessary to preserve uniqueness.
- Return type
None
-
forceupdate
(*args, **kw)¶ Like a bulk
forceput()
.- Return type
None
-
get
(k[, d]) → D[k] if k in D, else d. d defaults to None.¶
-
property
inv
¶ The inverse of this bidict.
- Return type
BidictBase
[~VT, ~KT]
-
property
inverse
¶ The inverse of this bidict.
- Return type
BidictBase
[~VT, ~KT]
-
items
() → a set-like object providing a view on D’s items¶
-
keys
() → a set-like object providing a view on D’s keys¶
-
move_to_end
(key, last=True)[source]¶ Move an existing key to the beginning or end of this ordered bidict.
The item is moved to the end if last is True, else to the beginning.
- Raises
KeyError – if the key does not exist
- Return type
None
-
on_dup
= OnDup(key=<DROP_OLD>, val=<RAISE>, kv=<RAISE>)¶
-
pop
(key, default=<_NONE>)¶ x.pop(k[, d]) → v
Remove specified key and return the corresponding value.
-
popitem
(last=True)[source]¶ x.popitem() → (k, v)
Remove and return the most recently added item as a (key, value) pair if last is True, else the least recently added item.
-
put
(key, val, on_dup=OnDup(key=<RAISE>, val=<RAISE>, kv=<RAISE>))¶ Associate key with val, honoring the
OnDup
given in on_dup.For example, if on_dup is
ON_DUP_RAISE
, then key will be associated with val if and only if key is not already associated with an existing value and val is not already associated with an existing key, otherwise an exception will be raised.If key is already associated with val, this is a no-op.
- Raises
bidict.KeyDuplicationError – if attempting to insert an item whose key only duplicates an existing item’s, and on_dup.key is
RAISE
.bidict.ValueDuplicationError – if attempting to insert an item whose value only duplicates an existing item’s, and on_dup.val is
RAISE
.bidict.KeyAndValueDuplicationError – if attempting to insert an item whose key duplicates one existing item’s, and whose value duplicates another existing item’s, and on_dup.kv is
RAISE
.
- Return type
None
-
putall
(items, on_dup=OnDup(key=<RAISE>, val=<RAISE>, kv=<RAISE>))¶ Like a bulk
put()
.If one of the given items causes an exception to be raised, none of the items is inserted.
- Return type
None
-
setdefault
(k[, d]) → D.get(k,d), also set D[k]=d if k not in D¶
-
values
()¶ A set-like object providing a view on the contained values.
Override the implementation inherited from
Mapping
. Because the values of aBidirectionalMapping
are the keys of its inverse, this returns aKeysView
rather than aValuesView
, which has the advantages of constant-time containment checks and supporting set operations.- Return type
AbstractSet
[~VT]
-
-
class
bidict.
OnDup
(key: bidict.OnDupAction = <DROP_OLD>, val: bidict.OnDupAction = <RAISE>, kv: bidict.OnDupAction = <RAISE>)¶ Bases:
bidict._dup._OnDup
A 3-tuple of
OnDupAction
s specifying how to handle the 3 kinds of duplication.See also Values Must Be Unique
If kv is not specified, val will be used for kv.
-
__add__
(value, /)¶ Return self+value.
-
__contains__
(key, /)¶ Return key in self.
-
__eq__
(value, /)¶ Return self==value.
-
__ge__
(value, /)¶ Return self>=value.
-
__getattribute__
(name, /)¶ Return getattr(self, name).
-
__getitem__
(key, /)¶ Return self[key].
-
__getnewargs__
()¶ Return self as a plain tuple. Used by copy and pickle.
-
__gt__
(value, /)¶ Return self>value.
-
__hash__
()¶ Return hash(self).
-
__iter__
()¶ Implement iter(self).
-
__le__
(value, /)¶ Return self<=value.
-
__len__
()¶ Return len(self).
-
__lt__
(value, /)¶ Return self<value.
-
__module__
= 'bidict'¶
-
__mul__
(value, /)¶ Return self*value.
-
__ne__
(value, /)¶ Return self!=value.
-
static
__new__
(cls, key=<DROP_OLD>, val=<RAISE>, kv=<RAISE>)[source]¶ Override to provide user-friendly default values.
- Return type
-
__repr__
()¶ Return a nicely formatted representation string
-
__rmul__
(value, /)¶ Return value*self.
-
__slots__
= ()¶
-
_asdict
()¶ Return a new OrderedDict which maps field names to their values.
-
_fields
= ('key', 'val', 'kv')¶
-
_fields_defaults
= {}¶
-
classmethod
_make
(iterable)¶ Make a new _OnDup object from a sequence or iterable
-
_replace
(**kwds)¶ Return a new _OnDup object replacing specified fields with new values
-
count
(value, /)¶ Return number of occurrences of value.
-
index
(value, start=0, stop=9223372036854775807, /)¶ Return first index of value.
Raises ValueError if the value is not present.
-
property
key
¶ Alias for field number 0
-
property
kv
¶ Alias for field number 2
-
property
val
¶ Alias for field number 1
-
-
class
bidict.
OnDupAction
(value)¶ Bases:
enum.Enum
An action to take to prevent duplication from occurring.
-
RAISE
= 'RAISE'¶
-
DROP_OLD
= 'DROP_OLD'¶
-
DROP_NEW
= 'DROP_NEW'¶
-
__module__
= 'bidict'¶
-
-
exception
bidict.
BidictException
¶ Bases:
Exception
Base class for bidict exceptions.
-
__cause__
¶ exception cause
-
__context__
¶ exception context
-
__delattr__
(name, /)¶ Implement delattr(self, name).
-
__dict__
= mappingproxy({'__module__': 'bidict', '__doc__': 'Base class for bidict exceptions.', '__weakref__': <attribute '__weakref__' of 'BidictException' objects>})¶
-
__getattribute__
(name, /)¶ Return getattr(self, name).
-
__init__
(*args, **kwargs)¶ Initialize self. See help(type(self)) for accurate signature.
-
__module__
= 'bidict'¶
-
__new__
(**kwargs)¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__
()¶ Helper for pickle.
-
__repr__
()¶ Return repr(self).
-
__setattr__
(name, value, /)¶ Implement setattr(self, name, value).
-
__setstate__
()¶
-
__str__
()¶ Return str(self).
-
__suppress_context__
¶
-
__traceback__
¶
-
__weakref__
¶ list of weak references to the object (if defined)
-
args
¶
-
with_traceback
()¶ Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
-
-
exception
bidict.
DuplicationError
¶ Bases:
bidict.BidictException
Base class for exceptions raised when uniqueness is violated as per the :attr:~bidict.RAISE`
OnDupAction
.-
__cause__
¶ exception cause
-
__context__
¶ exception context
-
__delattr__
(name, /)¶ Implement delattr(self, name).
-
__dict__
= mappingproxy({'__module__': 'bidict', '__doc__': 'Base class for exceptions raised when uniqueness is violated\n as per the :attr:~bidict.RAISE` :class:`~bidict.OnDupAction`.\n '})¶
-
__getattribute__
(name, /)¶ Return getattr(self, name).
-
__init__
(*args, **kwargs)¶ Initialize self. See help(type(self)) for accurate signature.
-
__module__
= 'bidict'¶
-
__new__
(**kwargs)¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__
()¶ Helper for pickle.
-
__repr__
()¶ Return repr(self).
-
__setattr__
(name, value, /)¶ Implement setattr(self, name, value).
-
__setstate__
()¶
-
__str__
()¶ Return str(self).
-
__suppress_context__
¶
-
__traceback__
¶
-
__weakref__
¶ list of weak references to the object (if defined)
-
args
¶
-
with_traceback
()¶ Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
-
-
exception
bidict.
KeyDuplicationError
¶ Bases:
bidict.DuplicationError
Raised when a given key is not unique.
-
__cause__
¶ exception cause
-
__context__
¶ exception context
-
__delattr__
(name, /)¶ Implement delattr(self, name).
-
__dict__
= mappingproxy({'__module__': 'bidict', '__doc__': 'Raised when a given key is not unique.'})¶
-
__getattribute__
(name, /)¶ Return getattr(self, name).
-
__init__
(*args, **kwargs)¶ Initialize self. See help(type(self)) for accurate signature.
-
__module__
= 'bidict'¶
-
__new__
(**kwargs)¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__
()¶ Helper for pickle.
-
__repr__
()¶ Return repr(self).
-
__setattr__
(name, value, /)¶ Implement setattr(self, name, value).
-
__setstate__
()¶
-
__str__
()¶ Return str(self).
-
__suppress_context__
¶
-
__traceback__
¶
-
__weakref__
¶ list of weak references to the object (if defined)
-
args
¶
-
with_traceback
()¶ Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
-
-
exception
bidict.
ValueDuplicationError
¶ Bases:
bidict.DuplicationError
Raised when a given value is not unique.
-
__cause__
¶ exception cause
-
__context__
¶ exception context
-
__delattr__
(name, /)¶ Implement delattr(self, name).
-
__dict__
= mappingproxy({'__module__': 'bidict', '__doc__': 'Raised when a given value is not unique.'})¶
-
__getattribute__
(name, /)¶ Return getattr(self, name).
-
__init__
(*args, **kwargs)¶ Initialize self. See help(type(self)) for accurate signature.
-
__module__
= 'bidict'¶
-
__new__
(**kwargs)¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__
()¶ Helper for pickle.
-
__repr__
()¶ Return repr(self).
-
__setattr__
(name, value, /)¶ Implement setattr(self, name, value).
-
__setstate__
()¶
-
__str__
()¶ Return str(self).
-
__suppress_context__
¶
-
__traceback__
¶
-
__weakref__
¶ list of weak references to the object (if defined)
-
args
¶
-
with_traceback
()¶ Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
-
-
exception
bidict.
KeyAndValueDuplicationError
¶ Bases:
bidict.KeyDuplicationError
,bidict.ValueDuplicationError
Raised when a given item’s key and value are not unique.
That is, its key duplicates that of another item, and its value duplicates that of a different other item.
-
__cause__
¶ exception cause
-
__context__
¶ exception context
-
__delattr__
(name, /)¶ Implement delattr(self, name).
-
__dict__
= mappingproxy({'__module__': 'bidict', '__doc__': "Raised when a given item's key and value are not unique.\n\n That is, its key duplicates that of another item,\n and its value duplicates that of a different other item.\n "})¶
-
__getattribute__
(name, /)¶ Return getattr(self, name).
-
__init__
(*args, **kwargs)¶ Initialize self. See help(type(self)) for accurate signature.
-
__module__
= 'bidict'¶
-
__new__
(**kwargs)¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__
()¶ Helper for pickle.
-
__repr__
()¶ Return repr(self).
-
__setattr__
(name, value, /)¶ Implement setattr(self, name, value).
-
__setstate__
()¶
-
__str__
()¶ Return str(self).
-
__suppress_context__
¶
-
__traceback__
¶
-
__weakref__
¶ list of weak references to the object (if defined)
-
args
¶
-
with_traceback
()¶ Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
-
-
bidict.
inverted
(arg)¶ Yield the inverse items of the provided object.
If arg has a
callable()
__inverted__
attribute, return the result of calling it.Otherwise, return an iterator over the items in arg, inverting each item on the fly.
-
bidict.
RAISE
= <RAISE>¶ An action to take to prevent duplication from occurring.
-
bidict.
DROP_OLD
= <DROP_OLD>¶ An action to take to prevent duplication from occurring.
-
bidict.
DROP_NEW
= <DROP_NEW>¶ An action to take to prevent duplication from occurring.
-
bidict.
ON_DUP_DEFAULT
= OnDup(key=<DROP_OLD>, val=<RAISE>, kv=<RAISE>)¶ A 3-tuple of
OnDupAction
s specifying how to handle the 3 kinds of duplication.See also Values Must Be Unique
If kv is not specified, val will be used for kv.
-
bidict.
ON_DUP_RAISE
= OnDup(key=<RAISE>, val=<RAISE>, kv=<RAISE>)¶ A 3-tuple of
OnDupAction
s specifying how to handle the 3 kinds of duplication.See also Values Must Be Unique
If kv is not specified, val will be used for kv.
-
bidict.
ON_DUP_DROP_OLD
= OnDup(key=<DROP_OLD>, val=<DROP_OLD>, kv=<DROP_OLD>)¶ A 3-tuple of
OnDupAction
s specifying how to handle the 3 kinds of duplication.See also Values Must Be Unique
If kv is not specified, val will be used for kv.
-
bidict._iter.
_iteritems_mapping_or_iterable
(arg)[source]¶ Yield the items in arg.
If arg is a
Mapping
, return an iterator over its items. Otherwise return an iterator over arg itself.
-
bidict._iter.
_iteritems_args_kw
(*args, **kw)[source]¶ Yield the items from the positional argument (if given) and then any from kw.
-
bidict.
__version__
¶ The version of bidict represented as a string.
-
bidict.
__version_info__
¶ The version of bidict represented as a tuple.