Skip to content

ENH pickle classes and objects with __slots__ #228

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

Merged
merged 2 commits into from
Jan 17, 2019

Conversation

pierreglaser
Copy link
Member

closes #225

Note that this this implementation will fail if the class __slots__ attribute is modified after the class creation.
Choosing to handle this case would lead to complex and tedious code, and I am not even sure we can guess correctly the existence of slots in every single case.
In addition, choosing not to handle this is consistent with python's choice: stating the documetation of the stdlib's copyreg._slotnames function:

This assumes classes don't modify their
__slots__ attribute to misrepresent their slots after the class is
defined.

@codecov-io
Copy link

codecov-io commented Jan 14, 2019

Codecov Report

Merging #228 into master will increase coverage by 0.18%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #228      +/-   ##
=========================================
+ Coverage   84.92%   85.1%   +0.18%     
=========================================
  Files           1       1              
  Lines         577     584       +7     
  Branches      114     117       +3     
=========================================
+ Hits          490     497       +7     
  Misses         63      63              
  Partials       24      24
Impacted Files Coverage Δ
cloudpickle/cloudpickle.py 85.1% <100%> (+0.18%) ⬆️

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 7fd15c2...80f03a6. Read the comment docs.

@pierreglaser pierreglaser changed the title ENH pickle classes and objects with __slots__ WIP ENH pickle classes and objects with __slots__ Jan 14, 2019
@pierreglaser pierreglaser changed the title WIP ENH pickle classes and objects with __slots__ [WIP] ENH pickle classes and objects with __slots__ Jan 14, 2019
Copy link

@pwais pwais left a comment

Choose a reason for hiding this comment

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

(not that my approval counts, but thank you for the quick fix!!)

@@ -1310,6 +1310,35 @@ def g(x):

self.assertEqual(f2.__annotations__, f.__annotations__)

def test_instance_with_slots(self):
Copy link

Choose a reason for hiding this comment

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

lg2m, thank you so much for taking this on!

@pierreglaser pierreglaser force-pushed the ENH_implement-slots-pickling branch from 9bf7281 to 878f1f6 Compare January 15, 2019 10:15
@pierreglaser pierreglaser force-pushed the ENH_implement-slots-pickling branch from 878f1f6 to 381e267 Compare January 15, 2019 10:17
@pierreglaser pierreglaser changed the title [WIP] ENH pickle classes and objects with __slots__ ENH pickle classes and objects with __slots__ Jan 15, 2019
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.

LGTM, please add an entry to the change log (for 0.7).

@ogrisel ogrisel merged commit 26341f5 into cloudpipe:master Jan 17, 2019
@ogrisel
Copy link
Contributor

ogrisel commented Jan 17, 2019

I merged too quickly: we don't want to introduce a new dependency on six just for string_types. Let me fix this in a new PR.

@pwais
Copy link

pwais commented Mar 4, 2019

woops, didn't see six. by the way, in thanks for fixing this issue, I made a donation to the project: https://opencollective.com/cloudpickle

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.

Pickling objects with __slots__ fails
4 participants