Skip to content

Commit

Permalink
Add __enter__ and __exit__ methods on Optimize class (#7477)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
BarrensZeppelin authored Dec 13, 2024
1 parent 1e5c59a commit b429562
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/api/python/z3/z3.py
Original file line number Diff line number Diff line change
Expand Up @@ -7991,6 +7991,13 @@ def __del__(self):
if self._on_models_id is not None:
del _on_models[self._on_models_id]

def __enter__(self):
self.push()
return self

def __exit__(self, *exc_info):
self.pop()

def set(self, *args, **keys):
"""Set a configuration option.
The method `help()` return a string containing all available options.
Expand Down

0 comments on commit b429562

Please sign in to comment.