Skip to content

FIX pickling for ABC in python3.7#189

Merged
ogrisel merged 7 commits intocloudpipe:masterfrom
tomMoral:FIX_abc_reduce
Aug 23, 2018
Merged

FIX pickling for ABC in python3.7#189
ogrisel merged 7 commits intocloudpipe:masterfrom
tomMoral:FIX_abc_reduce

Conversation

@tomMoral
Copy link
Contributor

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 using abc._get_dump and then re-register them. This does not conserve the cache but this does not seem to be an issue (it is only a matter of performance for the first call to issubclass).

@codecov-io
Copy link

codecov-io commented Aug 16, 2018

Codecov Report

Merging #189 into master will increase coverage by 0.28%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
cloudpickle/cloudpickle.py 84.38% <100%> (+0.28%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5141802...9ef24cf. Read the comment docs.

@tomMoral tomMoral force-pushed the FIX_abc_reduce branch 2 times, most recently from d485714 to 8fdbe68 Compare August 16, 2018 14:09
@tomMoral tomMoral force-pushed the FIX_abc_reduce branch 2 times, most recently from fd506e6 to c917956 Compare August 16, 2018 16:05
@tomMoral
Copy link
Contributor Author

The trick to get an up-to-date python3.7 release was given here!

Copy link
Contributor

@ogrisel ogrisel left a 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!


AbstractClass.register(tuple)

depickled_base = pickle_depickle(AbstractClass, protocol=self.protocol)
Copy link
Contributor

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)
...

Copy link
Contributor

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.

Copy link
Contributor

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.

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

python 3.7+

if "_abc_impl" in clsdict:
import abc
(registry, _, _, _) = abc._get_dump(obj)
clsdict["_abc_impl"] = [wr() for wr in registry]
Copy link
Contributor

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?

@ogrisel ogrisel merged commit 08410b1 into cloudpipe:master Aug 23, 2018
@ogrisel
Copy link
Contributor

ogrisel commented Aug 23, 2018

Thanks! Merged. However, I forgot to ask about adding an entry to the changelog. Can you please open a new PR for that?

@tomMoral tomMoral deleted the FIX_abc_reduce branch August 23, 2018 10:15
tomMoral added a commit to tomMoral/cloudpickle that referenced this pull request Aug 23, 2018
ogrisel pushed a commit that referenced this pull request Aug 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants