Skip to content

__eq__ operator overloading should be prepared to accept any type #2050

@mdboom

Description

@mdboom

Some of the __eq__ operators in cuda_core assuming that the rhs side will be the same type as the lhs. This will result in raising an AttributeError (or worse) rather than returning False.

We need to do something like this (across the whole codebase):

-    def __eq__(self : _StridedLayout, other : _StridedLayout) -> bool:
-        return self.itemsize == other.itemsize and self.slice_offset == other.slice_offset and _base_layout_equal(self.base, other.base)
+    def __eq__(self, other) -> bool:
+        if not isinstance(other, _StridedLayout):
+            return NotImplemented
+        cdef _StridedLayout _other = <_StridedLayout>other
+        return self.itemsize == _other.itemsize and self.slice_offset == _other.slice_offset and _base_layout_equal(self.base, _other.base)

(PS: Found as part of adding type checking)

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcuda.coreEverything related to the cuda.core moduletriageNeeds the team's attention

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions