Add minimal support mapping view types (just the type names, really).
diff --git a/prototyping/test_typing.py b/prototyping/test_typing.py
index be11eae..2457a25 100644
--- a/prototyping/test_typing.py
+++ b/prototyping/test_typing.py
@@ -937,6 +937,12 @@
assert isinstance({42}, t)
assert not isinstance({''}, t)
+ def test_mapping_views(self):
+ # TODO: These tests are kind of lame.
+ assert isinstance({}.keys(), typing.KeysView)
+ assert isinstance({}.items(), typing.ItemsView)
+ assert isinstance({}.values(), typing.ValuesView)
+
def test_dict(self):
assert issubclass(dict, typing.Dict)
assert isinstance({}, typing.Dict)
diff --git a/prototyping/typing.py b/prototyping/typing.py
index fbf6a88..5d71f15 100644
--- a/prototyping/typing.py
+++ b/prototyping/typing.py
@@ -2,8 +2,6 @@
# __all__ (should not include T, KT, VT)
# Support Python 3.2
# Make re, io submodules?
-# Collections:
-# - MappingView, KeysView, ItemsView, ValuesView
# Other things from mypy's typing.py:
# - Reversible, SupportsInt, SupportsFloat, SupportsAbs, SupportsRound
@@ -1068,9 +1066,6 @@
pass
-# TODO: View types.
-
-
class MutableMapping(Mapping, extra=collections.abc.MutableMapping):
pass
@@ -1122,6 +1117,23 @@
pass
+class MappingView(Sized, Iterable, extra=collections.abc.MappingView):
+ pass
+
+
+class KeysView(MappingView, Set[KT], extra=collections.abc.KeysView):
+ pass
+
+
+# TODO: Enable Set[Tuple[KT, VT]] instead of Generic[KT, VT].
+class ItemsView(MappingView, Generic[KT, VT], extra=collections.abc.ItemsView):
+ pass
+
+
+class ValuesView(MappingView, extra=collections.abc.ValuesView):
+ pass
+
+
class _DictMeta(GenericMeta):
def __instancecheck__(self, obj):