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

Make Gin dynamic class wrapping compatible with pickle. #116

Merged
merged 1 commit into from
Apr 15, 2021

Conversation

copybara-service[bot]
Copy link

Make Gin dynamic class wrapping compatible with pickle.

A new take on how to do this, since the wrapt approach also didn't end up working. This approach does the following:

When wrapping a class where mutation should be disallowed, this dynamically subclasses the class's metaclass, and intercepts/wraps its call.
However, this metaclass then returns an instance of the original type, which allows pickling to work.
To preserve proper signature checking, there are a few changes also to the general Gin wrapper function, to always use the signature associated with the right init/new function.

@google-cla google-cla bot added the cla: yes label Apr 14, 2021
@copybara-service copybara-service bot force-pushed the test_365965384 branch 2 times, most recently from 88a3f85 to d9316d2 Compare April 14, 2021 23:59
A new take on how to do this, since the wrapt approach also didn't end up working. This approach does the following:

When wrapping a class where mutation should be disallowed, this dynamically subclasses the class's metaclass, and intercepts/wraps its __call__.
However, this metaclass then returns an instance of the original type, which allows pickling to work.
To preserve proper signature checking, there are a few changes also to the general Gin wrapper function, to always use the signature associated with the right __init__/__new__ function.

PiperOrigin-RevId: 368536947
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant