The expression u != None (where u is a unit) seg faults
Opened this issue · 2 comments
This can be worked around by instead using "u is not None". But the seg fault is really still a bug.
From James:
pistol% git grep "operator==" | grep "i:"
lib/Support/auto_derivative.i: bool operator==(const AutoDerivative& V) const;
lib/Support/auto_derivative.i: bool operator==(const T& V) const;
lib/Support/unit.i: bool operator==(const Unit& U) const;
From Mike:
For what it is worth, there are only a few classes that have operator== defined at the python level:
pistol% git grep "operator==" | grep "i:"
lib/Support/auto_derivative.i: bool operator==(const AutoDerivative& V) const;
lib/Support/auto_derivative.i: bool operator==(const T& V) const;
lib/Support/unit.i: bool operator==(const Unit& U) const;
Perhaps the best fix would be to not directly expose this to python in swig. We can define a eq python function that handles this case.
The “is None” is actually the preferred python way, according to PEP 8 (see https://docs.quantifiedcode.com/python-anti-patterns/readability/comparison_to_none.html). But a seg fault is kind of an extreme response to doing this the other way ;->