diff options
author | Guido van Rossum <guido@python.org> | 2015-11-19 05:12:58 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2015-11-19 05:12:58 (GMT) |
commit | bb7c57c6cdc9e36a9b5875f5bcfd52a8df10b7ba (patch) | |
tree | 3ab34406c26a66d52a494e1604df07fbc7ea7ef6 /Lib/test/test_typing.py | |
parent | 6efc7e726fa225bdbdbc549a6e2799869b76c391 (diff) | |
download | cpython-bb7c57c6cdc9e36a9b5875f5bcfd52a8df10b7ba.zip cpython-bb7c57c6cdc9e36a9b5875f5bcfd52a8df10b7ba.tar.gz cpython-bb7c57c6cdc9e36a9b5875f5bcfd52a8df10b7ba.tar.bz2 |
Issue #25472: In B[<type>], insert B in front of __bases__, to make the __dict__ descriptor work.
Diffstat (limited to 'Lib/test/test_typing.py')
-rw-r--r-- | Lib/test/test_typing.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index a74ec07..dc4c152 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -1,4 +1,5 @@ from collections import namedtuple +import pickle import re import sys from unittest import TestCase, main @@ -583,6 +584,35 @@ class GenericTests(TestCase): self.assertEqual(repr(MySimpleMapping), __name__ + '.' + 'MySimpleMapping[~XK, ~XV]') + def test_dict(self): + T = TypeVar('T') + class B(Generic[T]): + pass + b = B() + b.foo = 42 + self.assertEqual(b.__dict__, {'foo': 42}) + class C(B[int]): + pass + c = C() + c.bar = 'abc' + self.assertEqual(c.__dict__, {'bar': 'abc'}) + + def test_pickle(self): + T = TypeVar('T') + class B(Generic[T]): + pass + global C # pickle wants to reference the class by name + class C(B[int]): + pass + c = C() + c.foo = 42 + c.bar = 'abc' + z = pickle.dumps(c) + x = pickle.loads(z) + self.assertEqual(x.foo, 42) + self.assertEqual(x.bar, 'abc') + self.assertEqual(x.__dict__, {'foo': 42, 'bar': 'abc'}) + def test_errors(self): with self.assertRaises(TypeError): B = SimpleMapping[XK, Any] |