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

DM-16957: Add pickle support to DataId class #112

Merged
merged 1 commit into from Dec 21, 2018
Merged

Conversation

andy-slac
Copy link
Contributor

No description provided.

Copy link
Member

@TallJimbo TallJimbo left a comment

Choose a reason for hiding this comment

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

It took me a while to convince myself this was correct, and that worries me a bit, but if it works for you, I'm okay with it.

Maybe it would be best to just add a comment noting (assuming this is actually right) that we just need to implement __getnewargs_ex__ in order to make __new__ run without error, because the automatic attribute-setting logic in unpickling replaces all of the state __new__ is usually responsible for initializing.

@andy-slac
Copy link
Contributor Author

I'll add that as a comment. Related question may be whether do we need that non-trivial __new__ or can we do it all in __init__?

@andy-slac
Copy link
Contributor Author

Just to add - I had to write a unit test for that to convince myself that it works as expected 🙂 Pickle stuff is not on my favorite tools list, I'd prefer to avoid specializing that if I could.

@TallJimbo
Copy link
Member

The reason I implemented __new__ is to shortcut the common+trivial case where we already have DataId and don't need a new one, by returning the given instance instead of a new one. I imagine we could avoid that by always going through a different named factory function.

@andy-slac
Copy link
Contributor Author

Dumb question - is it done for optimization only or does the code actually relies on identity of DataIds?

@TallJimbo
Copy link
Member

It should be optimization only (I wasn't sure it would be when I was originally writing this code, but I think it is now).

@timj timj deleted the tickets/DM-16957 branch April 22, 2020 22:02
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.

None yet

2 participants