Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types.MappingProxyType and collections.defaultdict #89030

Closed
guoci mannequin opened this issue Aug 8, 2021 · 2 comments
Closed

types.MappingProxyType and collections.defaultdict #89030

guoci mannequin opened this issue Aug 8, 2021 · 2 comments
Assignees
Labels
3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@guoci
Copy link
Mannequin

guoci mannequin commented Aug 8, 2021

BPO 44867
Nosy @rhettinger, @guoci

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/rhettinger'
closed_at = <Date 2021-08-08.20:19:44.313>
created_at = <Date 2021-08-08.19:16:15.848>
labels = ['type-bug', '3.8', '3.9', '3.10', '3.11', 'invalid', '3.7', 'library']
title = 'types.MappingProxyType and collections.defaultdict'
updated_at = <Date 2021-08-08.20:19:44.310>
user = 'https://github.com/guoci'

bugs.python.org fields:

activity = <Date 2021-08-08.20:19:44.310>
actor = 'rhettinger'
assignee = 'rhettinger'
closed = True
closed_date = <Date 2021-08-08.20:19:44.313>
closer = 'rhettinger'
components = ['Library (Lib)']
creation = <Date 2021-08-08.19:16:15.848>
creator = 'guoci'
dependencies = []
files = []
hgrepos = []
issue_num = 44867
keywords = []
message_count = 2.0
messages = ['399234', '399238']
nosy_count = 2.0
nosy_names = ['rhettinger', 'guoci']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue44867'
versions = ['Python 3.6', 'Python 3.7', 'Python 3.8', 'Python 3.9', 'Python 3.10', 'Python 3.11']

@guoci
Copy link
Mannequin Author

guoci mannequin commented Aug 8, 2021

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())])

@guoci guoci mannequin added 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Aug 8, 2021
@rhettinger
Copy link
Contributor

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.

Technically, the underlying mapping is modifying itself. That is allowed.

Also, there isn't really anything that the mapping proxy can do about it. All MappingProxy can do it forward calls to methods that are usually non-mutating.

@rhettinger rhettinger self-assigned this Aug 8, 2021
@rhettinger rhettinger self-assigned this Aug 8, 2021
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant