1- from typing import Type , Union
1+ from typing import Any
22
33import sys
44import pytest
@@ -24,7 +24,7 @@ def __eq__(self, other: object) -> bool:
2424 else :
2525 return NotImplemented
2626
27- def __ne__ (self , other : Self ) -> bool :
27+ def __ne__ (self , other : object ) -> bool :
2828 if isinstance (other , self .__class__ ):
2929 return self .x != other .x
3030 else :
@@ -33,13 +33,13 @@ def __ne__(self, other: Self) -> bool:
3333
3434@pytest .mark .skipif (
3535 sys .implementation .name == "graalpy"
36- and __graalpython__ .get_graalvm_version ().startswith ("24.1" ), # noqa: F821
36+ and __graalpython__ .get_graalvm_version ().startswith ("24.1" ), # type: ignore[name-defined] # noqa: F821
3737 reason = "Bug in GraalPy 24.1" ,
3838)
3939@pytest .mark .parametrize (
4040 "ty" , (Eq , EqDerived , PyEq ), ids = ("rust" , "rust-derived" , "python" )
4141)
42- def test_eq (ty : Type [ Union [ Eq , EqDerived , PyEq ]] ):
42+ def test_eq (ty : Any ):
4343 a = ty (0 )
4444 b = ty (0 )
4545 c = ty (1 )
@@ -78,12 +78,12 @@ class PyEqDefaultNe:
7878 def __init__ (self , x : int ) -> None :
7979 self .x = x
8080
81- def __eq__ (self , other : Self ) -> bool :
82- return self .x == other .x
81+ def __eq__ (self , other : object ) -> bool :
82+ return isinstance ( other , self . __class__ ) and self .x == other .x
8383
8484
8585@pytest .mark .parametrize ("ty" , (EqDefaultNe , PyEqDefaultNe ), ids = ("rust" , "python" ))
86- def test_eq_default_ne (ty : Type [ Union [ EqDefaultNe , PyEqDefaultNe ]] ):
86+ def test_eq_default_ne (ty : Any ):
8787 a = ty (0 )
8888 b = ty (0 )
8989 c = ty (1 )
@@ -121,10 +121,14 @@ def __lt__(self, other: Self) -> bool:
121121 def __le__ (self , other : Self ) -> bool :
122122 return self .x <= other .x
123123
124- def __eq__ (self , other : Self ) -> bool :
124+ def __eq__ (self , other : object ) -> bool :
125+ if not isinstance (other , self .__class__ ):
126+ return NotImplemented
125127 return self .x == other .x
126128
127- def __ne__ (self , other : Self ) -> bool :
129+ def __ne__ (self , other : object ) -> bool :
130+ if not isinstance (other , self .__class__ ):
131+ return NotImplemented
128132 return self .x != other .x
129133
130134 def __gt__ (self , other : Self ) -> bool :
@@ -139,7 +143,7 @@ def __ge__(self, other: Self) -> bool:
139143 (Ordered , OrderedDerived , OrderedRichCmp , PyOrdered ),
140144 ids = ("rust" , "rust-derived" , "rust-richcmp" , "python" ),
141145)
142- def test_ordered (ty : Type [ Union [ Ordered , OrderedDerived , OrderedRichCmp , PyOrdered ]] ):
146+ def test_ordered (ty : Any ):
143147 a = ty (0 )
144148 b = ty (0 )
145149 c = ty (1 )
@@ -174,7 +178,9 @@ def __lt__(self, other: Self) -> bool:
174178 def __le__ (self , other : Self ) -> bool :
175179 return self .x <= other .x
176180
177- def __eq__ (self , other : Self ) -> bool :
181+ def __eq__ (self , other : object ) -> bool :
182+ if not isinstance (other , self .__class__ ):
183+ return NotImplemented
178184 return self .x == other .x
179185
180186 def __gt__ (self , other : Self ) -> bool :
@@ -187,7 +193,7 @@ def __ge__(self, other: Self) -> bool:
187193@pytest .mark .parametrize (
188194 "ty" , (OrderedDefaultNe , PyOrderedDefaultNe ), ids = ("rust" , "python" )
189195)
190- def test_ordered_default_ne (ty : Type [ Union [ OrderedDefaultNe , PyOrderedDefaultNe ]] ):
196+ def test_ordered_default_ne (ty : Any ):
191197 a = ty (0 )
192198 b = ty (0 )
193199 c = ty (1 )
0 commit comments