ReFRACtor / framework

Base repository with generic software components
https://refractor.github.io/framework/
Other
10 stars 11 forks source link

The expression u != None (where u is a unit) seg faults #3

Open mikesmyth opened 4 years ago

mikesmyth commented 4 years ago

This can be worked around by instead using "u is not None". But the seg fault is really still a bug.

mikesmyth commented 4 years ago

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;

mikesmyth commented 4 years ago

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 ;->

Filed as Issue #3 (https://github.com/ReFRACtor/framework/issues/3), we should fix this at some point.