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

Should treat collections.Mapping keys/values like dict.keys/values #66

Open
wosc opened this issue Jan 16, 2020 · 1 comment
Open

Should treat collections.Mapping keys/values like dict.keys/values #66

wosc opened this issue Jan 16, 2020 · 1 comment

Comments

@wosc
Copy link
Contributor

wosc commented Jan 16, 2020

Basically something like

--- checker.py~	2019-04-23 14:47:56.000000000 +0200
+++ checker.py	2020-01-16 15:02:56.000000000 +0100
@@ -757,6 +757,18 @@
     _basic_types[type({}.keys())] = NoProxy
     _basic_types[type({}.items())] = NoProxy

+     class DummyMapping(collections.abc.Mapping):
+
+        def __getitem__(self, key):
+            raise KeyError(key)
+        def __iter__(self):
+            return iter(())
+        def __len__(self):
+            return 0
+    mydict = DummyMapping()
+    _basic_types[type(mydict.keys())] = NoProxy
+    _basic_types[type(mydict.values())] = NoProxy
+    _basic_types[type(mydict.items())] = NoProxy
+
 try:
     import pytz
 except ImportError:  # pragma: no cover
@jamadden
Copy link
Member

jamadden commented Feb 13, 2020

One possible issue with that: The dict view types are implemented in C (in CPython), and are truly immutable. But the Mapping view types (collections.abc.KeysView, collections.abc.ValuesView and collections.abc.ItemsView) are implemented in Python, and have an easily accessible _mapping attribute. With no proxy around them, the original mapping could be accessed and even mutated.

UPDATED to add: Maybe having interfaces for them (zopefoundation/zope.interface#175) will make writing normal security definitions easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants