@@ -504,6 +504,12 @@ def test_basics(self):
504504 with self .assertRaises (TypeError ):
505505 Y [str , str ]
506506
507+ def test_generic_errors (self ):
508+ with self .assertRaises (TypeError ):
509+ isinstance ([], List [int ])
510+ with self .assertRaises (TypeError ):
511+ issubclass (list , List [int ])
512+
507513 def test_init (self ):
508514 T = TypeVar ('T' )
509515 S = TypeVar ('S' )
@@ -753,39 +759,6 @@ def test_no_isinstance(self):
753759 issubclass (int , ClassVar )
754760
755761
756- class VarianceTests (BaseTestCase ):
757-
758- def test_invariance (self ):
759- # Because of invariance, List[subclass of X] is not a subclass
760- # of List[X], and ditto for MutableSequence.
761- self .assertNotIsSubclass (typing .List [Manager ], typing .List [Employee ])
762- self .assertNotIsSubclass (typing .MutableSequence [Manager ],
763- typing .MutableSequence [Employee ])
764- # It's still reflexive.
765- self .assertIsSubclass (typing .List [Employee ], typing .List [Employee ])
766- self .assertIsSubclass (typing .MutableSequence [Employee ],
767- typing .MutableSequence [Employee ])
768-
769- def test_covariance_sequence (self ):
770- # Check covariance for Sequence (which is just a generic class
771- # for this purpose, but using a type variable with covariant=True).
772- self .assertIsSubclass (typing .Sequence [Manager ],
773- typing .Sequence [Employee ])
774- self .assertNotIsSubclass (typing .Sequence [Employee ],
775- typing .Sequence [Manager ])
776-
777- def test_covariance_mapping (self ):
778- # Ditto for Mapping (covariant in the value, invariant in the key).
779- self .assertIsSubclass (typing .Mapping [Employee , Manager ],
780- typing .Mapping [Employee , Employee ])
781- self .assertNotIsSubclass (typing .Mapping [Manager , Employee ],
782- typing .Mapping [Employee , Employee ])
783- self .assertNotIsSubclass (typing .Mapping [Employee , Manager ],
784- typing .Mapping [Manager , Manager ])
785- self .assertNotIsSubclass (typing .Mapping [Manager , Employee ],
786- typing .Mapping [Manager , Manager ])
787-
788-
789762class CastTests (BaseTestCase ):
790763
791764 def test_basics (self ):
@@ -1122,7 +1095,6 @@ def test_iterable(self):
11221095 # path and could fail. So call this a few times.
11231096 self .assertIsInstance ([], typing .Iterable )
11241097 self .assertIsInstance ([], typing .Iterable )
1125- self .assertIsInstance ([], typing .Iterable [int ])
11261098 self .assertNotIsInstance (42 , typing .Iterable )
11271099 # Just in case, also test issubclass() a few times.
11281100 self .assertIsSubclass (list , typing .Iterable )
@@ -1131,7 +1103,6 @@ def test_iterable(self):
11311103 def test_iterator (self ):
11321104 it = iter ([])
11331105 self .assertIsInstance (it , typing .Iterator )
1134- self .assertIsInstance (it , typing .Iterator [int ])
11351106 self .assertNotIsInstance (42 , typing .Iterator )
11361107
11371108 @skipUnless (PY35 , 'Python 3.5 required' )
@@ -1332,10 +1303,6 @@ def foo():
13321303 yield 42
13331304 g = foo ()
13341305 self .assertIsSubclass (type (g ), typing .Generator )
1335- self .assertIsSubclass (typing .Generator [Manager , Employee , Manager ],
1336- typing .Generator [Employee , Manager , Employee ])
1337- self .assertNotIsSubclass (typing .Generator [Manager , Manager , Manager ],
1338- typing .Generator [Employee , Employee , Employee ])
13391306
13401307 def test_no_generator_instantiation (self ):
13411308 with self .assertRaises (TypeError ):
0 commit comments