diff options
author | Mathieu Bridon <[email protected]> | 2018-08-09 10:27:18 +0200 |
---|---|---|
committer | Dylan Baker <[email protected]> | 2018-08-10 08:45:59 -0700 |
commit | 15ac05fd45afb0d85f1806a77fc9ec47f4949f01 (patch) | |
tree | b75de3b5f0d6f55a299acf1c310a5565958375b2 /src/gallium/auxiliary/util | |
parent | e94095ec30462d4264c6d7c7dd4fbf8bc0d99c69 (diff) |
python: Fix inequality comparisons
On Python 3, executing `foo != bar` will first try to call
foo.__ne__(bar), and fallback on the opposite result of foo.__eq__(bar).
Python 2 does not do that.
As a result, those __eq__ methods were never called, when we were
testing for inequality.
Expliclty adding the __ne__ methods fixes this issue, in a way that is
compatible with both Python 2 and 3.
However, this means the __eq__ methods are now called when testing for
`foo != None`, so they need to be guarded correctly.
Signed-off-by: Mathieu Bridon <[email protected]>
Reviewed-by: Dylan Baker <[email protected]>
Diffstat (limited to 'src/gallium/auxiliary/util')
-rw-r--r-- | src/gallium/auxiliary/util/u_format_parse.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/gallium/auxiliary/util/u_format_parse.py b/src/gallium/auxiliary/util/u_format_parse.py index d3874cd895b..48cc012cd2a 100644 --- a/src/gallium/auxiliary/util/u_format_parse.py +++ b/src/gallium/auxiliary/util/u_format_parse.py @@ -72,8 +72,14 @@ class Channel: return s def __eq__(self, other): + if other is None: + return False + return self.type == other.type and self.norm == other.norm and self.pure == other.pure and self.size == other.size + def __ne__(self, other): + return not self == other + def max(self): '''Maximum representable number.''' if self.type == FLOAT: |