mirror of
https://github.com/python/cpython.git
synced 2025-11-03 11:23:31 +00:00
If using a frozen class with slots, add __getstate__ and __setstate__ to set the instance values. (GH-25786)
This commit is contained in:
parent
f82fd77717
commit
823fbf4e0e
2 changed files with 34 additions and 2 deletions
|
|
@ -2833,6 +2833,19 @@ class TestSlots(unittest.TestCase):
|
|||
self.assertFalse(hasattr(A, "__slots__"))
|
||||
self.assertTrue(hasattr(B, "__slots__"))
|
||||
|
||||
# Can't be local to test_frozen_pickle.
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class FrozenSlotsClass:
|
||||
foo: str
|
||||
bar: int
|
||||
|
||||
def test_frozen_pickle(self):
|
||||
# bpo-43999
|
||||
|
||||
assert self.FrozenSlotsClass.__slots__ == ("foo", "bar")
|
||||
p = pickle.dumps(self.FrozenSlotsClass("a", 1))
|
||||
assert pickle.loads(p) == self.FrozenSlotsClass("a", 1)
|
||||
|
||||
|
||||
class TestDescriptors(unittest.TestCase):
|
||||
def test_set_name(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue