On this page
types.MappingProxyType
Prev: types.LambdaType | Up: types | Next: types.MemberDescriptorType
Rel: types.AsyncGeneratorType, types.BuiltinFunctionType, types.BuiltinMethodType, types.CapsuleType
Ref: docs.python.org — types.MappingProxyType
Tags: #public #python3 #stdlib #types
Import
import types
from types import MappingProxyType
Signature & Overview
types.MappingProxyType(mapping)
Read-only proxy of a mapping.
Methods & Attributes
MappingProxyType.copy(self, /)— D.copy() -> a shallow copy of DMappingProxyType.get(self, key, default=None, /)— Return the value for key if key is in the mapping, else default.MappingProxyType.items(self, /)— D.items() -> a set-like object providing a view on D's itemsMappingProxyType.keys(self, /)— D.keys() -> a set-like object providing a view on D's keysMappingProxyType.values(self, /)— D.values() -> an object providing a view on D's values
Usage
import types
backing = {'a': 1, 'b': 2}
ro = types.MappingProxyType(backing)
assert ro['a'] == 1
try:
ro['a'] = 9
except TypeError:
assert True
Gotchas
- Read-only live view, NOT a frozen copy: Mutating
backingstill reflects inro(great for exposing read-only dicts without copying).
REPL Inspect
from types import MappingProxyType
help(MappingProxyType)
Linked from
Related notes
- tuts/python3/stdlib_module/types/LambdaType Linked here; links to this page; shared tags: #stdlib, #types
- tuts/python3/stdlib_module/types/MemberDescriptorType Linked here; links to this page; shared tags: #stdlib, #types
- tuts/python3/stdlib_module/types Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/types/AsyncGeneratorType Linked here; shared tags: #stdlib, #types
- tuts/python3/stdlib_module/types/BuiltinFunctionType Linked here; shared tags: #stdlib, #types
- tuts/python3/stdlib_module/types/BuiltinMethodType Linked here; shared tags: #stdlib, #types
- tuts/python3/stdlib_module/types/CapsuleType Linked here; shared tags: #stdlib, #types
- tuts/c/stdlib/stdint_stdbool_and_limits shared tags: #stdlib, #types
- tuts/python3/stdlib_module/types/CellType shared tags: #stdlib, #types
- tuts/python3/stdlib_module/types/ClassMethodDescriptorType shared tags: #stdlib, #types