Quoting Mathieu Bridon (2018-07-05 06:17:43) > 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 <boche...@daitauha.fr> > --- > src/amd/vulkan/vk_format_parse.py | 6 ++++++ > src/gallium/auxiliary/util/u_format_parse.py | 6 ++++++ > src/mesa/main/format_parser.py | 6 ++++++ > 3 files changed, 18 insertions(+) > > diff --git a/src/amd/vulkan/vk_format_parse.py > b/src/amd/vulkan/vk_format_parse.py > index 00cf1adf5a..778eae61ba 100644 > --- a/src/amd/vulkan/vk_format_parse.py > +++ b/src/amd/vulkan/vk_format_parse.py > @@ -73,8 +73,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 and self.scaled == > other.scaled > > + def __ne__(self, other): > + return not self.__eq__(other)
This can be written as "not (self == other)", right? > + > def max(self): > '''Maximum representable number.''' > if self.type == FLOAT: > diff --git a/src/gallium/auxiliary/util/u_format_parse.py > b/src/gallium/auxiliary/util/u_format_parse.py > index 315c771081..e60b317e08 100644 > --- a/src/gallium/auxiliary/util/u_format_parse.py > +++ b/src/gallium/auxiliary/util/u_format_parse.py > @@ -69,8 +69,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.__eq__(other) > + > def max(self): > '''Maximum representable number.''' > if self.type == FLOAT: > diff --git a/src/mesa/main/format_parser.py b/src/mesa/main/format_parser.py > index 3321ad33ff..c0d73c9d22 100644 > --- a/src/mesa/main/format_parser.py > +++ b/src/mesa/main/format_parser.py > @@ -61,8 +61,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.size == other.size > > + def __ne__(self, other): > + return not self.__eq__(other) > + > def max(self): > """Returns the maximum representable number.""" > if self.type == FLOAT: > -- > 2.17.1 > > _______________________________________________ > mesa-dev mailing list > mesa-dev@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/mesa-dev
signature.asc
Description: signature
_______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev