summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_typing.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2016-11-29 17:46:21 (GMT)
committerGuido van Rossum <guido@python.org>2016-11-29 17:46:21 (GMT)
commit61f0a0261f0fbfd0a6b981c370a8808aad00b107 (patch)
tree2e5068d5f4686c608561ee54fbacf6d1e4dc3ea2 /Lib/test/test_typing.py
parent47a9a4bedaa343e72898b2c7534d27f3e0cf4ff5 (diff)
downloadcpython-61f0a0261f0fbfd0a6b981c370a8808aad00b107.zip
cpython-61f0a0261f0fbfd0a6b981c370a8808aad00b107.tar.gz
cpython-61f0a0261f0fbfd0a6b981c370a8808aad00b107.tar.bz2
Issue #28790: Fix error when using Generic and __slots__ (Ivan L)
Diffstat (limited to 'Lib/test/test_typing.py')
-rw-r--r--Lib/test/test_typing.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index 0910fd4..d203ce3 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -896,6 +896,44 @@ class GenericTests(BaseTestCase):
self.assertEqual(t, copy(t))
self.assertEqual(t, deepcopy(t))
+ def test_parameterized_slots(self):
+ T = TypeVar('T')
+ class C(Generic[T]):
+ __slots__ = ('potato',)
+
+ c = C()
+ c_int = C[int]()
+ self.assertEqual(C.__slots__, C[str].__slots__)
+
+ c.potato = 0
+ c_int.potato = 0
+ with self.assertRaises(AttributeError):
+ c.tomato = 0
+ with self.assertRaises(AttributeError):
+ c_int.tomato = 0
+
+ def foo(x: C['C']): ...
+ self.assertEqual(get_type_hints(foo, globals(), locals())['x'], C[C])
+ self.assertEqual(get_type_hints(foo, globals(), locals())['x'].__slots__,
+ C.__slots__)
+ self.assertEqual(copy(C[int]), deepcopy(C[int]))
+
+ def test_parameterized_slots_dict(self):
+ T = TypeVar('T')
+ class D(Generic[T]):
+ __slots__ = {'banana': 42}
+
+ d = D()
+ d_int = D[int]()
+ self.assertEqual(D.__slots__, D[str].__slots__)
+
+ d.banana = 'yes'
+ d_int.banana = 'yes'
+ with self.assertRaises(AttributeError):
+ d.foobar = 'no'
+ with self.assertRaises(AttributeError):
+ d_int.foobar = 'no'
+
def test_errors(self):
with self.assertRaises(TypeError):
B = SimpleMapping[XK, Any]