mirror of
https://github.com/Z3Prover/z3
synced 2025-04-23 09:05:31 +00:00
Added __nonzero__ and __bool__ functions to Python Z3 ASTs to enable use of Python lists (and similar).
Thanks to Vlad Shcherbina for the recommendation (see 37679447 (comment62859886_37679447)
)!
This commit is contained in:
parent
47f97dde89
commit
a2eb824590
1 changed files with 13 additions and 0 deletions
|
@ -292,6 +292,19 @@ class AstRef(Z3PPObject):
|
|||
def __hash__(self):
|
||||
return self.hash()
|
||||
|
||||
def __nonzero__(self):
|
||||
return self.__bool__()
|
||||
|
||||
def __bool__(self):
|
||||
if is_true(self):
|
||||
return True
|
||||
elif is_false(self):
|
||||
return False
|
||||
elif is_eq(self) and self.num_args() == 2:
|
||||
return self.arg(0).eq(self.arg(1))
|
||||
else:
|
||||
raise Z3Exception("Symbolic expressions cannot be cast to concrete Boolean values.")
|
||||
|
||||
def sexpr(self):
|
||||
"""Return an string representing the AST node in s-expression notation.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue