[New-bugs-announce] [issue44867] types.MappingProxyType and collections.defaultdict

Guo Ci Teo report at bugs.python.org
Sun Aug 8 15:16:15 EDT 2021


New submission from Guo Ci Teo <zguoci at gmail.com>:

`types.MappingProxyType` is documented as 'Read-only proxy of a mapping'.
But if used with a `collections.defaultdict` mapping, it can modify the underlying mapping.
```
import collections, types
dd = collections.defaultdict(set)
mpt = types.MappingProxyType(dd)
mpt['__getitem__'] # key inserted
mpt.get('get') # key not inserted
print(dd.items()) # dict_items([('__getitem__', set())])
```

----------
components: Library (Lib)
messages: 399234
nosy: guoci
priority: normal
severity: normal
status: open
title: types.MappingProxyType and collections.defaultdict
type: behavior
versions: Python 3.10, Python 3.11, Python 3.6, Python 3.7, Python 3.8, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44867>
_______________________________________


More information about the New-bugs-announce mailing list