From 3ae61376f82c8f3517f49bf3928908bd5f4eac6d Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Tue, 24 Jan 2017 19:01:00 -0800 Subject: [PATCH 1/9] Add typing.Counter Pretty much copied from deque. --- python2/test_typing.py | 11 +++++++++++ python2/typing.py | 10 ++++++++++ src/test_typing.py | 11 +++++++++++ src/typing.py | 10 ++++++++++ 4 files changed, 42 insertions(+) diff --git a/python2/test_typing.py b/python2/test_typing.py index 42e82cb57..58d74a5f3 100644 --- a/python2/test_typing.py +++ b/python2/test_typing.py @@ -1264,6 +1264,9 @@ def test_list(self): def test_deque(self): self.assertIsSubclass(collections.deque, typing.Deque) + def test_counter(self): + self.assertIsSubclass(collections.Counter, typing.Counter) + def test_set(self): self.assertIsSubclass(set, typing.Set) self.assertNotIsSubclass(frozenset, typing.Set) @@ -1338,6 +1341,14 @@ def test_deque_instantiation(self): class D(typing.Deque[T]): pass self.assertIs(type(D[int]()), D) + def test_no_counter_instantiation(self): + with self.assertRaises(TypeError): + typing.Counter() + with self.assertRaises(TypeError): + typing.Counter[T]() + with self.assertRaises(TypeError): + typing.Counter[int]() + def test_no_set_instantiation(self): with self.assertRaises(TypeError): typing.Set() diff --git a/python2/typing.py b/python2/typing.py index 6b137c4ef..e7382d24b 100644 --- a/python2/typing.py +++ b/python2/typing.py @@ -53,6 +53,7 @@ 'SupportsInt', # Concrete collection types. + 'Counter', 'Deque', 'Dict', 'DefaultDict', @@ -1717,6 +1718,15 @@ def __new__(cls, *args, **kwds): return collections.deque(*args, **kwds) return _generic_new(collections.deque, cls, *args, **kwds) +class Counter(collections.Counter, MutableSequence[T]): + __slots__ = () + __extra__ = collections.Counter + + def __new__(cls, *args, **kwds): + if _geqv(cls, Counter): + raise TypeError("Type Counter cannot be instantiated; " + "use Counter() instead") + return _generic_new(collections.Counter, cls, *args, **kwds) class Set(set, MutableSet[T]): __slots__ = () diff --git a/src/test_typing.py b/src/test_typing.py index 0935af0af..9517b6b72 100644 --- a/src/test_typing.py +++ b/src/test_typing.py @@ -1662,6 +1662,9 @@ def test_list(self): def test_deque(self): self.assertIsSubclass(collections.deque, typing.Deque) + def test_counter(self): + self.assertIsSubclass(collections.Counter, typing.Counter) + def test_set(self): self.assertIsSubclass(set, typing.Set) self.assertNotIsSubclass(frozenset, typing.Set) @@ -1736,6 +1739,14 @@ def test_deque_instantiation(self): class D(typing.Deque[T]): ... self.assertIs(type(D[int]()), D) + def test_no_counter_instantiation(self): + with self.assertRaises(TypeError): + typing.Counter() + with self.assertRaises(TypeError): + typing.Counter[T]() + with self.assertRaises(TypeError): + typing.Counter[int]() + def test_no_set_instantiation(self): with self.assertRaises(TypeError): typing.Set() diff --git a/src/typing.py b/src/typing.py index 964dec76b..6a9b41ed7 100644 --- a/src/typing.py +++ b/src/typing.py @@ -62,6 +62,7 @@ 'SupportsRound', # Concrete collection types. + 'Counter', 'Deque', 'Dict', 'DefaultDict', @@ -1828,6 +1829,15 @@ def __new__(cls, *args, **kwds): return collections.deque(*args, **kwds) return _generic_new(collections.deque, cls, *args, **kwds) +class Counter(collections.Counter, MutableSequence[T], extra=collections.Counter): + + __slots__ = () + + def __new__(cls, *args, **kwds): + if _geqv(cls, Counter): + raise TypeError("Type Counter cannot be instantiated; " + "use Counter() instead") + return _generic_new(collections.Counter, cls, *args, **kwds) class Set(set, MutableSet[T], extra=set): From 4f5ad2c705288c5c991fa46916f8f7681e907313 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Tue, 24 Jan 2017 19:08:00 -0800 Subject: [PATCH 2/9] also add ChainMap Only to the Python 3 version because ChainMap was added in 3.3. --- src/test_typing.py | 22 ++++++++++++++++++++++ src/typing.py | 11 +++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/test_typing.py b/src/test_typing.py index 9517b6b72..9cc2ded3b 100644 --- a/src/test_typing.py +++ b/src/test_typing.py @@ -892,6 +892,9 @@ class MyDict(typing.Dict[T, T]): ... class MyDef(typing.DefaultDict[str, T]): ... self.assertIs(MyDef[int]().__class__, MyDef) self.assertIs(MyDef[int]().__orig_class__, MyDef[int]) + class MyChain(typing.ChainMap[str, T]): ... + self.assertIs(MyChain[int]().__class__, MyChain) + self.assertIs(MyChain[int]().__orig_class__, MyChain[int]) def test_all_repr_eq_any(self): objs = (getattr(typing, el) for el in typing.__all__) @@ -1732,6 +1735,25 @@ class MyDefDict(typing.DefaultDict[str, int]): self.assertIsSubclass(MyDefDict, collections.defaultdict) self.assertNotIsSubclass(collections.defaultdict, MyDefDict) + def test_no_chainmap_instantiation(self): + with self.assertRaises(TypeError): + typing.ChainMap() + with self.assertRaises(TypeError): + typing.ChainMap[KT, VT]() + with self.assertRaises(TypeError): + typing.ChainMap[str, int]() + + def test_chainmap_subclass(self): + + class MyChainMap(typing.ChainMap[str, int]): + pass + + cm = MyChainMap() + self.assertIsInstance(cm, MyChainMap) + + self.assertIsSubclass(MyChainMap, collections.ChainMap) + self.assertNotIsSubclass(collections.ChainMap, MyChainMap) + def test_deque_instantiation(self): self.assertIs(type(typing.Deque()), collections.deque) self.assertIs(type(typing.Deque[T]()), collections.deque) diff --git a/src/typing.py b/src/typing.py index 6a9b41ed7..56ded19d8 100644 --- a/src/typing.py +++ b/src/typing.py @@ -62,6 +62,7 @@ 'SupportsRound', # Concrete collection types. + 'ChainMap', 'Counter', 'Deque', 'Dict', @@ -1907,6 +1908,16 @@ def __new__(cls, *args, **kwds): return collections.defaultdict(*args, **kwds) return _generic_new(collections.defaultdict, cls, *args, **kwds) +class ChainMap(collections.ChainMap, MutableMapping[KT, VT], + extra=collections.ChainMap): + + __slots__ = () + + def __new__(cls, *args, **kwds): + if _geqv(cls, ChainMap): + raise TypeError("Type ChainMap cannot be instantiated; " + "use collections.ChainMap() instead") + return _generic_new(collections.ChainMap, cls, *args, **kwds) # Determine what base class to use for Generator. if hasattr(collections_abc, 'Generator'): From a0baeb3260101538c3cd7443f73357b90383f0cd Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Tue, 24 Jan 2017 19:50:19 -0800 Subject: [PATCH 3/9] fix for 3.2 Apparently typing still supports 3.2 --- src/test_typing.py | 5 +++++ src/typing.py | 21 ++++++++++++--------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/test_typing.py b/src/test_typing.py index 9cc2ded3b..9c65078bc 100644 --- a/src/test_typing.py +++ b/src/test_typing.py @@ -892,6 +892,9 @@ class MyDict(typing.Dict[T, T]): ... class MyDef(typing.DefaultDict[str, T]): ... self.assertIs(MyDef[int]().__class__, MyDef) self.assertIs(MyDef[int]().__orig_class__, MyDef[int]) + + @skipUnless(sys.version_info >= (3, 3), 'ChainMap was added in 3.3') + def test_chainmap_type_erasure_special(self): class MyChain(typing.ChainMap[str, T]): ... self.assertIs(MyChain[int]().__class__, MyChain) self.assertIs(MyChain[int]().__orig_class__, MyChain[int]) @@ -1735,6 +1738,7 @@ class MyDefDict(typing.DefaultDict[str, int]): self.assertIsSubclass(MyDefDict, collections.defaultdict) self.assertNotIsSubclass(collections.defaultdict, MyDefDict) + @skipUnless(sys.version_info >= (3, 3), 'ChainMap was added in 3.3') def test_no_chainmap_instantiation(self): with self.assertRaises(TypeError): typing.ChainMap() @@ -1743,6 +1747,7 @@ def test_no_chainmap_instantiation(self): with self.assertRaises(TypeError): typing.ChainMap[str, int]() + @skipUnless(sys.version_info >= (3, 3), 'ChainMap was added in 3.3') def test_chainmap_subclass(self): class MyChainMap(typing.ChainMap[str, int]): diff --git a/src/typing.py b/src/typing.py index 56ded19d8..13e361a2a 100644 --- a/src/typing.py +++ b/src/typing.py @@ -62,7 +62,6 @@ 'SupportsRound', # Concrete collection types. - 'ChainMap', 'Counter', 'Deque', 'Dict', @@ -1908,16 +1907,20 @@ def __new__(cls, *args, **kwds): return collections.defaultdict(*args, **kwds) return _generic_new(collections.defaultdict, cls, *args, **kwds) -class ChainMap(collections.ChainMap, MutableMapping[KT, VT], - extra=collections.ChainMap): +if hasattr(collections, 'ChainMap'): + # ChainMap only exists in 3.3+ + __all__.append('ChainMap') - __slots__ = () + class ChainMap(collections.ChainMap, MutableMapping[KT, VT], + extra=collections.ChainMap): - def __new__(cls, *args, **kwds): - if _geqv(cls, ChainMap): - raise TypeError("Type ChainMap cannot be instantiated; " - "use collections.ChainMap() instead") - return _generic_new(collections.ChainMap, cls, *args, **kwds) + __slots__ = () + + def __new__(cls, *args, **kwds): + if _geqv(cls, ChainMap): + raise TypeError("Type ChainMap cannot be instantiated; " + "use collections.ChainMap() instead") + return _generic_new(collections.ChainMap, cls, *args, **kwds) # Determine what base class to use for Generator. if hasattr(collections_abc, 'Generator'): From 622ddfcac45d9ef6025cc162667f3c9018a5ce43 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Tue, 24 Jan 2017 19:53:25 -0800 Subject: [PATCH 4/9] fix flake8 --- python2/typing.py | 2 ++ src/typing.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/python2/typing.py b/python2/typing.py index e7382d24b..42a979e88 100644 --- a/python2/typing.py +++ b/python2/typing.py @@ -1718,6 +1718,7 @@ def __new__(cls, *args, **kwds): return collections.deque(*args, **kwds) return _generic_new(collections.deque, cls, *args, **kwds) + class Counter(collections.Counter, MutableSequence[T]): __slots__ = () __extra__ = collections.Counter @@ -1728,6 +1729,7 @@ def __new__(cls, *args, **kwds): "use Counter() instead") return _generic_new(collections.Counter, cls, *args, **kwds) + class Set(set, MutableSet[T]): __slots__ = () __extra__ = set diff --git a/src/typing.py b/src/typing.py index 13e361a2a..d551b641d 100644 --- a/src/typing.py +++ b/src/typing.py @@ -1829,6 +1829,7 @@ def __new__(cls, *args, **kwds): return collections.deque(*args, **kwds) return _generic_new(collections.deque, cls, *args, **kwds) + class Counter(collections.Counter, MutableSequence[T], extra=collections.Counter): __slots__ = () @@ -1839,6 +1840,7 @@ def __new__(cls, *args, **kwds): "use Counter() instead") return _generic_new(collections.Counter, cls, *args, **kwds) + class Set(set, MutableSet[T], extra=set): __slots__ = () @@ -1907,6 +1909,7 @@ def __new__(cls, *args, **kwds): return collections.defaultdict(*args, **kwds) return _generic_new(collections.defaultdict, cls, *args, **kwds) + if hasattr(collections, 'ChainMap'): # ChainMap only exists in 3.3+ __all__.append('ChainMap') @@ -1922,6 +1925,7 @@ def __new__(cls, *args, **kwds): "use collections.ChainMap() instead") return _generic_new(collections.ChainMap, cls, *args, **kwds) + # Determine what base class to use for Generator. if hasattr(collections_abc, 'Generator'): # Sufficiently recent versions of 3.5 have a Generator ABC. From dd0eb3dc82dca89eabd11bff6cf3c7bd7fb06754 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Fri, 27 Jan 2017 20:06:49 -0800 Subject: [PATCH 5/9] fix base class of Counter --- python2/typing.py | 2 +- src/typing.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/python2/typing.py b/python2/typing.py index 42a979e88..351985f65 100644 --- a/python2/typing.py +++ b/python2/typing.py @@ -1719,7 +1719,7 @@ def __new__(cls, *args, **kwds): return _generic_new(collections.deque, cls, *args, **kwds) -class Counter(collections.Counter, MutableSequence[T]): +class Counter(collections.Counter, Dict[T, int]): __slots__ = () __extra__ = collections.Counter diff --git a/src/typing.py b/src/typing.py index d551b641d..6f851b489 100644 --- a/src/typing.py +++ b/src/typing.py @@ -1830,7 +1830,7 @@ def __new__(cls, *args, **kwds): return _generic_new(collections.deque, cls, *args, **kwds) -class Counter(collections.Counter, MutableSequence[T], extra=collections.Counter): +class Counter(collections.Counter, Dict[T, int], extra=collections.Counter): __slots__ = () From c0f748a1dcf5258badd3efabd93d53dc5fa3b1ea Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Fri, 27 Jan 2017 20:13:16 -0800 Subject: [PATCH 6/9] move counter below Dict --- python2/typing.py | 22 +++++++++++----------- src/typing.py | 22 +++++++++++----------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/python2/typing.py b/python2/typing.py index 351985f65..420591150 100644 --- a/python2/typing.py +++ b/python2/typing.py @@ -1719,17 +1719,6 @@ def __new__(cls, *args, **kwds): return _generic_new(collections.deque, cls, *args, **kwds) -class Counter(collections.Counter, Dict[T, int]): - __slots__ = () - __extra__ = collections.Counter - - def __new__(cls, *args, **kwds): - if _geqv(cls, Counter): - raise TypeError("Type Counter cannot be instantiated; " - "use Counter() instead") - return _generic_new(collections.Counter, cls, *args, **kwds) - - class Set(set, MutableSet[T]): __slots__ = () __extra__ = set @@ -1795,6 +1784,17 @@ def __new__(cls, *args, **kwds): return _generic_new(collections.defaultdict, cls, *args, **kwds) +class Counter(collections.Counter, Dict[T, int]): + __slots__ = () + __extra__ = collections.Counter + + def __new__(cls, *args, **kwds): + if _geqv(cls, Counter): + raise TypeError("Type Counter cannot be instantiated; " + "use Counter() instead") + return _generic_new(collections.Counter, cls, *args, **kwds) + + # Determine what base class to use for Generator. if hasattr(collections_abc, 'Generator'): # Sufficiently recent versions of 3.5 have a Generator ABC. diff --git a/src/typing.py b/src/typing.py index 6f851b489..52c0bf019 100644 --- a/src/typing.py +++ b/src/typing.py @@ -1830,17 +1830,6 @@ def __new__(cls, *args, **kwds): return _generic_new(collections.deque, cls, *args, **kwds) -class Counter(collections.Counter, Dict[T, int], extra=collections.Counter): - - __slots__ = () - - def __new__(cls, *args, **kwds): - if _geqv(cls, Counter): - raise TypeError("Type Counter cannot be instantiated; " - "use Counter() instead") - return _generic_new(collections.Counter, cls, *args, **kwds) - - class Set(set, MutableSet[T], extra=set): __slots__ = () @@ -1910,6 +1899,17 @@ def __new__(cls, *args, **kwds): return _generic_new(collections.defaultdict, cls, *args, **kwds) +class Counter(collections.Counter, Dict[T, int], extra=collections.Counter): + + __slots__ = () + + def __new__(cls, *args, **kwds): + if _geqv(cls, Counter): + raise TypeError("Type Counter cannot be instantiated; " + "use Counter() instead") + return _generic_new(collections.Counter, cls, *args, **kwds) + + if hasattr(collections, 'ChainMap'): # ChainMap only exists in 3.3+ __all__.append('ChainMap') From 5c5c2e7534013ef905d71aa91a5a336a5d5cf576 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sat, 28 Jan 2017 09:02:55 -0800 Subject: [PATCH 7/9] clarify error message, add test --- python2/test_typing.py | 10 ++++++++++ python2/typing.py | 2 +- src/test_typing.py | 10 ++++++++++ src/typing.py | 2 +- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/python2/test_typing.py b/python2/test_typing.py index 58d74a5f3..7fe0de16c 100644 --- a/python2/test_typing.py +++ b/python2/test_typing.py @@ -1349,6 +1349,16 @@ def test_no_counter_instantiation(self): with self.assertRaises(TypeError): typing.Counter[int]() + def test_counter_subclass_instantiation(self): + + class MyCounter(typing.Counter[int]): + pass + + d = MyCounter() + self.assertIsInstance(d, MyCounter) + self.assertIsInstance(d, typing.Counter) + self.assertIsInstance(d, collections.Counter) + def test_no_set_instantiation(self): with self.assertRaises(TypeError): typing.Set() diff --git a/python2/typing.py b/python2/typing.py index 420591150..13d1ce2a5 100644 --- a/python2/typing.py +++ b/python2/typing.py @@ -1791,7 +1791,7 @@ class Counter(collections.Counter, Dict[T, int]): def __new__(cls, *args, **kwds): if _geqv(cls, Counter): raise TypeError("Type Counter cannot be instantiated; " - "use Counter() instead") + "use collections.Counter() instead") return _generic_new(collections.Counter, cls, *args, **kwds) diff --git a/src/test_typing.py b/src/test_typing.py index 9c65078bc..cb102edd2 100644 --- a/src/test_typing.py +++ b/src/test_typing.py @@ -1774,6 +1774,16 @@ def test_no_counter_instantiation(self): with self.assertRaises(TypeError): typing.Counter[int]() + def test_counter_subclass_instantiation(self): + + class MyCounter(typing.Counter[int]): + pass + + d = MyCounter() + self.assertIsInstance(d, MyCounter) + self.assertIsInstance(d, typing.Counter) + self.assertIsInstance(d, collections.Counter) + def test_no_set_instantiation(self): with self.assertRaises(TypeError): typing.Set() diff --git a/src/typing.py b/src/typing.py index 52c0bf019..be9ee0423 100644 --- a/src/typing.py +++ b/src/typing.py @@ -1906,7 +1906,7 @@ class Counter(collections.Counter, Dict[T, int], extra=collections.Counter): def __new__(cls, *args, **kwds): if _geqv(cls, Counter): raise TypeError("Type Counter cannot be instantiated; " - "use Counter() instead") + "use collections.Counter() instead") return _generic_new(collections.Counter, cls, *args, **kwds) From 3dfbaf9cc01f54e3b4ef02b8ae532325a961b15d Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Tue, 31 Jan 2017 07:26:56 -0800 Subject: [PATCH 8/9] allow instantiation --- python2/test_typing.py | 13 ++++++------- python2/typing.py | 3 +-- src/test_typing.py | 26 ++++++++++++-------------- src/typing.py | 6 ++---- 4 files changed, 21 insertions(+), 27 deletions(-) diff --git a/python2/test_typing.py b/python2/test_typing.py index 7fe0de16c..156199057 100644 --- a/python2/test_typing.py +++ b/python2/test_typing.py @@ -1341,13 +1341,12 @@ def test_deque_instantiation(self): class D(typing.Deque[T]): pass self.assertIs(type(D[int]()), D) - def test_no_counter_instantiation(self): - with self.assertRaises(TypeError): - typing.Counter() - with self.assertRaises(TypeError): - typing.Counter[T]() - with self.assertRaises(TypeError): - typing.Counter[int]() + def test_counter_instantiation(self): + self.assertIs(type(typing.Counter()), collections.Counter) + self.assertIs(type(typing.Counter[T]()), collections.Counter) + self.assertIs(type(typing.Counter[int]()), collections.Counter) + class C(typing.Counter[T]): pass + self.assertIs(type(C[int]()), C) def test_counter_subclass_instantiation(self): diff --git a/python2/typing.py b/python2/typing.py index 13d1ce2a5..a865263c0 100644 --- a/python2/typing.py +++ b/python2/typing.py @@ -1790,8 +1790,7 @@ class Counter(collections.Counter, Dict[T, int]): def __new__(cls, *args, **kwds): if _geqv(cls, Counter): - raise TypeError("Type Counter cannot be instantiated; " - "use collections.Counter() instead") + return collections.Counter(*args, **kwds) return _generic_new(collections.Counter, cls, *args, **kwds) diff --git a/src/test_typing.py b/src/test_typing.py index cb102edd2..4cd91c2ca 100644 --- a/src/test_typing.py +++ b/src/test_typing.py @@ -1739,13 +1739,12 @@ class MyDefDict(typing.DefaultDict[str, int]): self.assertNotIsSubclass(collections.defaultdict, MyDefDict) @skipUnless(sys.version_info >= (3, 3), 'ChainMap was added in 3.3') - def test_no_chainmap_instantiation(self): - with self.assertRaises(TypeError): - typing.ChainMap() - with self.assertRaises(TypeError): - typing.ChainMap[KT, VT]() - with self.assertRaises(TypeError): - typing.ChainMap[str, int]() + def test_chainmap_instantiation(self): + self.assertIs(type(typing.ChainMap()), collections.ChainMap) + self.assertIs(type(typing.ChainMap[KT, VT]()), collections.ChainMap) + self.assertIs(type(typing.ChainMap[str, int]()), collections.ChainMap) + class CM(typing.ChainMap[KT, VT]): ... + self.assertIs(type(CM[int, str]()), CM) @skipUnless(sys.version_info >= (3, 3), 'ChainMap was added in 3.3') def test_chainmap_subclass(self): @@ -1766,13 +1765,12 @@ def test_deque_instantiation(self): class D(typing.Deque[T]): ... self.assertIs(type(D[int]()), D) - def test_no_counter_instantiation(self): - with self.assertRaises(TypeError): - typing.Counter() - with self.assertRaises(TypeError): - typing.Counter[T]() - with self.assertRaises(TypeError): - typing.Counter[int]() + def test_counter_instantiation(self): + self.assertIs(type(typing.Counter()), collections.Counter) + self.assertIs(type(typing.Counter[T]()), collections.Counter) + self.assertIs(type(typing.Counter[int]()), collections.Counter) + class C(typing.Counter[T]): ... + self.assertIs(type(C[int]()), C) def test_counter_subclass_instantiation(self): diff --git a/src/typing.py b/src/typing.py index be9ee0423..af10ab4dc 100644 --- a/src/typing.py +++ b/src/typing.py @@ -1905,8 +1905,7 @@ class Counter(collections.Counter, Dict[T, int], extra=collections.Counter): def __new__(cls, *args, **kwds): if _geqv(cls, Counter): - raise TypeError("Type Counter cannot be instantiated; " - "use collections.Counter() instead") + return collections.Counter(*args, **kwds) return _generic_new(collections.Counter, cls, *args, **kwds) @@ -1921,8 +1920,7 @@ class ChainMap(collections.ChainMap, MutableMapping[KT, VT], def __new__(cls, *args, **kwds): if _geqv(cls, ChainMap): - raise TypeError("Type ChainMap cannot be instantiated; " - "use collections.ChainMap() instead") + return collections.ChainMap(*args, **kwds) return _generic_new(collections.ChainMap, cls, *args, **kwds) From cbb42d9c24797471520f3ab5a38baca2f7f5ee8f Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sun, 5 Feb 2017 07:49:03 -0800 Subject: [PATCH 9/9] fix reliance on type cache --- src/test_typing.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/test_typing.py b/src/test_typing.py index 4cd91c2ca..20006a0c8 100644 --- a/src/test_typing.py +++ b/src/test_typing.py @@ -892,12 +892,11 @@ class MyDict(typing.Dict[T, T]): ... class MyDef(typing.DefaultDict[str, T]): ... self.assertIs(MyDef[int]().__class__, MyDef) self.assertIs(MyDef[int]().__orig_class__, MyDef[int]) - - @skipUnless(sys.version_info >= (3, 3), 'ChainMap was added in 3.3') - def test_chainmap_type_erasure_special(self): - class MyChain(typing.ChainMap[str, T]): ... - self.assertIs(MyChain[int]().__class__, MyChain) - self.assertIs(MyChain[int]().__orig_class__, MyChain[int]) + # ChainMap was added in 3.3 + if sys.version_info >= (3, 3): + class MyChain(typing.ChainMap[str, T]): ... + self.assertIs(MyChain[int]().__class__, MyChain) + self.assertIs(MyChain[int]().__orig_class__, MyChain[int]) def test_all_repr_eq_any(self): objs = (getattr(typing, el) for el in typing.__all__)