Disallow instantiating concrete types (List etc.).
diff --git a/prototyping/test_typing.py b/prototyping/test_typing.py
index a796931..6fda301 100644
--- a/prototyping/test_typing.py
+++ b/prototyping/test_typing.py
@@ -1122,6 +1122,46 @@
assert not isinstance({'': 42}, t)
assert not isinstance({'': ''}, t)
+ def test_no_list_instantiation(self):
+ with self.assertRaises(TypeError):
+ typing.List()
+ with self.assertRaises(TypeError):
+ typing.List[T]()
+ with self.assertRaises(TypeError):
+ typing.List[int]()
+
+ def test_no_dict_instantiation(self):
+ with self.assertRaises(TypeError):
+ typing.Dict()
+ with self.assertRaises(TypeError):
+ typing.Dict[KT, VT]()
+ with self.assertRaises(TypeError):
+ typing.Dict[str, int]()
+
+ def test_no_set_instantiation(self):
+ with self.assertRaises(TypeError):
+ typing.Set()
+ with self.assertRaises(TypeError):
+ typing.Set[T]()
+ with self.assertRaises(TypeError):
+ typing.Set[int]()
+
+ def test_no_frozenset_instantiation(self):
+ with self.assertRaises(TypeError):
+ typing.FrozenSet()
+ with self.assertRaises(TypeError):
+ typing.FrozenSet[T]()
+ with self.assertRaises(TypeError):
+ typing.FrozenSet[int]()
+
+ def test_no_tuple_instantiation(self):
+ with self.assertRaises(TypeError):
+ Tuple()
+ with self.assertRaises(TypeError):
+ Tuple[T]()
+ with self.assertRaises(TypeError):
+ Tuple[int]()
+
class NamedTupleTests(TestCase):
diff --git a/prototyping/typing.py b/prototyping/typing.py
index 73decb7..75634b7 100644
--- a/prototyping/typing.py
+++ b/prototyping/typing.py
@@ -1428,7 +1428,9 @@
class List(list, MutableSequence, metaclass=_ListMeta):
- pass
+
+ def __new__(self, *args, **kwds):
+ raise TypeError("Type List cannot be instantiated; use list() instead")
class _SetMeta(GenericMeta):
@@ -1444,7 +1446,9 @@
class Set(set, MutableSet, metaclass=_SetMeta):
- pass
+
+ def __new__(self, *args, **kwds):
+ raise TypeError("Type Set cannot be instantiated; use set() instead")
class _FrozenSetMeta(_SetMeta):
@@ -1467,7 +1471,9 @@
class FrozenSet(frozenset, AbstractSet, metaclass=_FrozenSetMeta):
- pass
+
+ def __new__(self, *args, **kwds):
+ raise TypeError("Type FrozenSet cannot be instantiated; use frozenset() instead")
class MappingView(Sized, Iterable, extra=collections_abc.MappingView):
@@ -1502,7 +1508,9 @@
class Dict(dict, MutableMapping, metaclass=_DictMeta):
- pass
+
+ def __new__(self, *args, **kwds):
+ raise TypeError("Type Dict cannot be instantiated; use dict() instead")
def NamedTuple(typename, fields):