FrozenOrderedDict¶
About¶
FrozenOrderedDict
is a immutable wrapper around an OrderedDict
.
It is similar to frozendict
, and with regards to immutability it solves the same problems:
Because dictionaries are mutable, they are not hashable and cannot be used in sets or as dictionary keys.
Nasty bugs can and do occur when mutable data structures are passed around.
It can be initialized just like a dict
or OrderedDict
.
Once instantiated, an instance of FrozenOrderedDict
cannot be altered,
since it does not implement the MutableMapping
interface.
FrozenOrderedDict
implements the
Mapping
interface, so can be used like a normal dictionary in most cases.
In order to modify the contents of a FrozenOrderedDict
, a new
instance must be created. The easiest way to do that is by
calling the .copy()
method. It will return a new instance of
FrozenOrderedDict
initialized using the following steps:
A copy of the wrapped
OrderedDict
instance will be created.If any arguments or keyword arguments are passed to the
.copy()
method, they will be used to create anotherOrderedDict
instance, which will then be used to update the copy made in step #1.Finally,
self.__class__()
will be called, passing the copy as the only argument.
API Reference¶
-
class
FrozenOrderedDict
(*args, **kwargs)[source]¶ Bases:
FrozenBase
[~KT
,~VT
]An immutable OrderedDict. It can be used as a drop-in replacement for dictionaries where immutability is desired.
Methods:
__contains__
(key)Return
key in self
.__getitem__
(key)Return
self[key]
.copy
(*args, **kwargs)Return a copy of the
FrozenOrderedDict
.get
(k[, default])Return the value for
k
ifk
is in the dictionary, elsedefault
.items
()Returns a set-like object providing a view on the
FrozenOrderedDict
's items.keys
()Returns a set-like object providing a view on the
FrozenOrderedDict
's keys.values
()Returns an object providing a view on the
FrozenOrderedDict
's values.-
copy
(*args, **kwargs)[source]¶ Return a copy of the
FrozenOrderedDict
.- Parameters
args
kwargs
-
items
()[source]¶ Returns a set-like object providing a view on the
FrozenOrderedDict
's items.- Return type
AbstractSet
[Tuple
[~KT
,~VT
]]
-
keys
()[source]¶ Returns a set-like object providing a view on the
FrozenOrderedDict
's keys.- Return type
-
values
()[source]¶ Returns an object providing a view on the
FrozenOrderedDict
's values.- Return type
-
Copyright¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.