-
Notifications
You must be signed in to change notification settings - Fork 167
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
FIX pickling for ABC in python3.7 #189
Conversation
Codecov Report
@@ Coverage Diff @@
## master #189 +/- ##
==========================================
+ Coverage 84.09% 84.38% +0.28%
==========================================
Files 1 1
Lines 547 557 +10
Branches 99 104 +5
==========================================
+ Hits 460 470 +10
Misses 63 63
Partials 24 24
Continue to review full report at Codecov.
|
5acea3a
to
654ea89
Compare
d485714
to
8fdbe68
Compare
fd506e6
to
c917956
Compare
The trick to get an up-to-date python3.7 release was given here! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments but other than that LGTM. Thanks for the fix!
tests/cloudpickle_test.py
Outdated
@@ -655,11 +655,16 @@ class ConcreteClass(AbstractClass): | |||
def foo(self): | |||
return 'it works!' | |||
|
|||
AbstractClass.register(tuple) | |||
|
|||
depickled_base = pickle_depickle(AbstractClass, protocol=self.protocol) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This introduces a side effect in the test. I don't think it's possible to unregister tuple. Cloud you please instead use a new locally defined class, e.g.:
class SomeOtherClass(object):
pass
AbstractClass.register(SomeOtherClass)
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, it should also be possible to do:
AbstractClass.register(tuple)
try:
...
finally:
AbstractClass._abc_registry_clear()
do as you wish.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We would also need to clean the registry of depickled_base
. Better not register tuple
at all.
cloudpickle/cloudpickle.py
Outdated
@@ -460,6 +460,14 @@ def save_dynamic_class(self, obj): | |||
clsdict = dict(obj.__dict__) # copy dict proxy to a dict | |||
clsdict.pop('__weakref__', None) | |||
|
|||
# For ABCMeta in python3.7, remove _abc_impl as it is not picklable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
python 3.7+
cloudpickle/cloudpickle.py
Outdated
if "_abc_impl" in clsdict: | ||
import abc | ||
(registry, _, _, _) = abc._get_dump(obj) | ||
clsdict["_abc_impl"] = [wr() for wr in registry] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does wr
stand for?
Thanks! Merged. However, I forgot to ask about adding an entry to the changelog. Can you please open a new PR for that? |
Fix #180
The issue was that the
abc
module have been entirely re-written in C. (python/cpython#5273)The
register
mechanism is not accessible anymore. The proposed implementation simply pickle the registered classes usingabc._get_dump
and then re-register them. This does not conserve thecache
but this does not seem to be an issue (it is only a matter of performance for the first call toissubclass
).