It looks like z3 expression has a hash()
method but not __hash__()
. Is there a reason why not using __hash__()
? This allows the expression to be hashable.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
There is no reason for not calling it
__hash__()
. I called ithash()
because I'm new to Python. I will add__hash__()
in the next release (Z3 4.2).EDIT: as pointed out in the comments, we also need
__eq__
or__cmp__
to be able to use a Z3 object as a key in a Python dictionary. Unfortunately, the__eq__
method (defined atExprRef
) is used to build Z3 expressions. That is, ifa
andb
are referencing Z3 expressions, thena == b
returns the Z3 expression object representing the expressiona = b
. This "feature" is convenient for writing Z3 examples in Python, but it has a nasty side-effect: the Python dictionary class will assume that all Z3 expressions are equal to each other. Actually, it is even worse, since the Python dictionary only invokes the method__eq__
for objects that have the same hashcode. Thus, if we define__hash__()
we may have the illusion that is safe to use Z3 expression objects as keys in Python dictionaries. For this reason, I will not include__hash__()
in the classAstRef
. Users that want to use Z3 expressions as keys in dictionaries may use the following trick: