-
-
Notifications
You must be signed in to change notification settings - Fork 75
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
Allow Parameterized.param.update
to be used as a context manager for temporary updates
#779
Conversation
I should have chimed in #685 back in February, or maybe at the time it was not so obvious to me, but I think that How about modifying class _Update:
def __init__(self, instance):
self.instance = instance
def __call__(self, **kwargs):
self.restore = self.instance.kwargs
self.instance._update(**kwargs)
return self
def __enter__(self):
print('ENTER')
def __exit__(self, *exc_details):
print('EXIT')
self.instance._update(**self.restore)
self.restore.clear()
class Parameters:
def __init__(self):
self.kwargs = dict(a=1)
def update(self, **kwargs):
return _Update(instance=self)(**kwargs)
def _update(self, **kwargs):
self.kwargs = kwargs If we don't go down that route, we should try to align |
What do you think about that @philippjfr ? |
I'll play around with it. |
Made the changes you requested, ready to review. |
Parameterized.param.update
to be used as a context manager for temporary updates
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR looked good to me overall, I completed it with:
- more tests
- updated docs
- making ParametersRestore private
Thanks!
Implements #685