@@ -910,6 +910,11 @@ class MyDict(typing.Dict[T, T]): ...
910910 class MyDef (typing .DefaultDict [str , T ]): ...
911911 self .assertIs (MyDef [int ]().__class__ , MyDef )
912912 self .assertIs (MyDef [int ]().__orig_class__ , MyDef [int ])
913+ # ChainMap was added in 3.3
914+ if sys .version_info >= (3 , 3 ):
915+ class MyChain (typing .ChainMap [str , T ]): ...
916+ self .assertIs (MyChain [int ]().__class__ , MyChain )
917+ self .assertIs (MyChain [int ]().__orig_class__ , MyChain [int ])
913918
914919 def test_all_repr_eq_any (self ):
915920 objs = (getattr (typing , el ) for el in typing .__all__ )
@@ -1705,6 +1710,9 @@ def test_deque(self):
17051710 class MyDeque (typing .Deque [int ]): ...
17061711 self .assertIsInstance (MyDeque (), collections .deque )
17071712
1713+ def test_counter (self ):
1714+ self .assertIsSubclass (collections .Counter , typing .Counter )
1715+
17081716 def test_set (self ):
17091717 self .assertIsSubclass (set , typing .Set )
17101718 self .assertNotIsSubclass (frozenset , typing .Set )
@@ -1772,13 +1780,50 @@ class MyDefDict(typing.DefaultDict[str, int]):
17721780 self .assertIsSubclass (MyDefDict , collections .defaultdict )
17731781 self .assertNotIsSubclass (collections .defaultdict , MyDefDict )
17741782
1783+ @skipUnless (sys .version_info >= (3 , 3 ), 'ChainMap was added in 3.3' )
1784+ def test_chainmap_instantiation (self ):
1785+ self .assertIs (type (typing .ChainMap ()), collections .ChainMap )
1786+ self .assertIs (type (typing .ChainMap [KT , VT ]()), collections .ChainMap )
1787+ self .assertIs (type (typing .ChainMap [str , int ]()), collections .ChainMap )
1788+ class CM (typing .ChainMap [KT , VT ]): ...
1789+ self .assertIs (type (CM [int , str ]()), CM )
1790+
1791+ @skipUnless (sys .version_info >= (3 , 3 ), 'ChainMap was added in 3.3' )
1792+ def test_chainmap_subclass (self ):
1793+
1794+ class MyChainMap (typing .ChainMap [str , int ]):
1795+ pass
1796+
1797+ cm = MyChainMap ()
1798+ self .assertIsInstance (cm , MyChainMap )
1799+
1800+ self .assertIsSubclass (MyChainMap , collections .ChainMap )
1801+ self .assertNotIsSubclass (collections .ChainMap , MyChainMap )
1802+
17751803 def test_deque_instantiation (self ):
17761804 self .assertIs (type (typing .Deque ()), collections .deque )
17771805 self .assertIs (type (typing .Deque [T ]()), collections .deque )
17781806 self .assertIs (type (typing .Deque [int ]()), collections .deque )
17791807 class D (typing .Deque [T ]): ...
17801808 self .assertIs (type (D [int ]()), D )
17811809
1810+ def test_counter_instantiation (self ):
1811+ self .assertIs (type (typing .Counter ()), collections .Counter )
1812+ self .assertIs (type (typing .Counter [T ]()), collections .Counter )
1813+ self .assertIs (type (typing .Counter [int ]()), collections .Counter )
1814+ class C (typing .Counter [T ]): ...
1815+ self .assertIs (type (C [int ]()), C )
1816+
1817+ def test_counter_subclass_instantiation (self ):
1818+
1819+ class MyCounter (typing .Counter [int ]):
1820+ pass
1821+
1822+ d = MyCounter ()
1823+ self .assertIsInstance (d , MyCounter )
1824+ self .assertIsInstance (d , typing .Counter )
1825+ self .assertIsInstance (d , collections .Counter )
1826+
17821827 def test_no_set_instantiation (self ):
17831828 with self .assertRaises (TypeError ):
17841829 typing .Set ()
0 commit comments