Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialize _abc_data. #585

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dill/_dill.py
Original file line number Diff line number Diff line change
Expand Up @@ -1768,6 +1768,8 @@ def save_type(pickler, obj, postproc_list=None):

for name in slots:
_dict.pop(name, None)
if isinstance(obj, abc.ABCMeta) and '_abc_impl' in _dict:
del _dict['_abc_impl']

qualname = getattr(obj, '__qualname__', None)
if attrs is not None:
Expand Down
20 changes: 20 additions & 0 deletions dill/tests/test_classdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# License: 3-clause BSD. The full license text is available at:
# - https://github.com/uqfoundation/dill/blob/master/LICENSE

import abc
import dill
from enum import EnumMeta
import sys
Expand Down Expand Up @@ -276,6 +277,24 @@ def test_enummeta():
assert dill.copy(HTTPStatus.OK) is HTTPStatus.OK
assert dill.copy(enum.EnumMeta) is enum.EnumMeta

def test_abc_data():
class MyMeta(metaclass=abc.ABCMeta):
_not_abc_impl = 1
# Make sure dill tries to serialise the class, not just pickle it by name.
# It needs to be in __main__ for dill to serialise it.
MyMeta.__module__ = '__main__'
class MyImpl:
pass
MyMeta.register(MyImpl)

assert isinstance (MyImpl(), MyMeta)
cls = dill.loads(dill.dumps(MyMeta))
# Dill doesn't serialise the ABC registry, although it's not clear if
# that's on purpose or not.
assert not isinstance (MyImpl(), cls)
cls.register(MyImpl)
assert isinstance (MyImpl(), cls)

if __name__ == '__main__':
test_class_instances()
test_class_objects()
Expand All @@ -289,3 +308,4 @@ def test_enummeta():
test_origbases()
test_metaclass()
test_enummeta()
test_abc_data()