Skip to content

Commit b429562

Browse files
Add __enter__ and __exit__ methods on Optimize class (#7477)
This enables the use of the with statement for the Optimize class to concisely call push() and pop(). This works similarly to the Solver class.
1 parent 1e5c59a commit b429562

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/api/python/z3/z3.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7991,6 +7991,13 @@ def __del__(self):
79917991
if self._on_models_id is not None:
79927992
del _on_models[self._on_models_id]
79937993

7994+
def __enter__(self):
7995+
self.push()
7996+
return self
7997+
7998+
def __exit__(self, *exc_info):
7999+
self.pop()
8000+
79948001
def set(self, *args, **keys):
79958002
"""Set a configuration option.
79968003
The method `help()` return a string containing all available options.

0 commit comments

Comments
 (0)