Skip to content

Conversation

@copybara-service
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
@copybara-service copybara-service bot closed this Apr 15, 2021
@copybara-service copybara-service bot deleted the test_365965384 branch April 15, 2021 00:00
@copybara-service copybara-service bot merged commit 6c641be into master Apr 15, 2021
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