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

Revert enthought/traits#373: instance traits are no longer pickleable #462

Merged
merged 2 commits into from
Apr 15, 2019

Conversation

mdickinson
Copy link
Member

@mdickinson mdickinson commented Apr 15, 2019

#373 made instance traits (not Instance traits![*]) pickleable. While the aim was a good one, the change introduced a variety of unintended consequences and breakages, so I'm reverting it here. We may be able to do it again properly one day.

The main issues are:

  1. Pickling instance traits requires that the corresponding TraitType objects are pickleable (whereas for class-level traits, we only need to pickle the trait values). Many TraitType objects currently aren't pickleable, especially in Python 2. That could certainly be fixed: see Make some previously-unpickleable trait types pickleable. #457 for some work in that direction, but there's much more to do.

  2. Even in the absence of use of add_trait (which is relatively rare in most Traits projects), the _instance_traits dictionary has entries added to it whenever a listener is attached to a class trait on a HasTraits object: the instance trait acts as the place to register listeners that are specific to that instance. This meant that Resolve pickling and deepcopying bug with dynamically added traits #373 resulted in attempts to pickle various (as it turns out unpickleable) class-level traits, breaking existing code. This again, could be fixed, at the cost of some work and some restructuring.

Point 2 is what causes the unexpected breakage of previously working code.

I'll re-open the various issues that were closed by #373.

[*] Not "Instance" traits! This issue is about traits added directly to an object (e.g., with HasTraits.add_trait), as opposed to traits declared at class level.

Closes #452

@mdickinson
Copy link
Member Author

And in case, like me, you're wondering why #373 added 35 lines and this PR removes 37, the blackening of the codebase in #432 introduced two extra blank lines following local imports.

@codecov-io
Copy link

Codecov Report

Merging #462 into master will decrease coverage by 0.02%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #462      +/-   ##
==========================================
- Coverage   65.29%   65.26%   -0.03%     
==========================================
  Files          44       44              
  Lines        7065     7057       -8     
  Branches     1413     1411       -2     
==========================================
- Hits         4613     4606       -7     
+ Misses       2029     2025       -4     
- Partials      423      426       +3
Impacted Files Coverage Δ
traits/has_traits.py 67.37% <ø> (-0.44%) ⬇️
traits/trait_base.py 55.79% <0%> (-2.18%) ⬇️
traits/traits.py 60% <0%> (-0.2%) ⬇️
traits/trait_handlers.py 63.07% <0%> (-0.14%) ⬇️
traits/etsconfig/etsconfig.py 63.58% <0%> (+6.17%) ⬆️

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 6e2581d...9d9c50e. Read the comment docs.

Copy link
Contributor

@corranwebster corranwebster left a comment

Choose a reason for hiding this comment

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

Looks good. The only line in the original PR that is not removed is an import of TraitError which appears to be used by other tests and so is still needed.

@mdickinson
Copy link
Member Author

Thanks for the review!

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 on Python 2 broken for many classes
4 participants