@@ -115,41 +115,27 @@ cdef class AbstractCondition(ConditionComponent):
115115 self.child_vector_id = - 1
116116 self.parent_vector_id = - 1
117117
118- def __richcmp__ (self , other: Any , int op ) :
118+ def __eq__ (self , other: Any ) -> bool :
119119 """
120- Todo: With Cython 2.7 this function can be replaced by using the six
121- Python special methods (__eq__(), __lt__(),...).
122- (--> https://cython.readthedocs.io/en/latest/src/userguide/special_methods.html\
123- #rich-comparisons)
124-
125- Before 2.7 there were no separate methods for the individual rich
126- comparison operations. Instead there is a single method __richcmp__()
127- which takes an integer indicating which operation is to be performed,
128- as follows:
129- < 0
130- == 2
131- > 4
132- <= 1
133- != 3
134- >= 5
135- """
136- if isinstance (other, self .__class__):
120+ This method implements a comparison between self and another
121+ object.
137122
138- if op == 2 :
139- if self .child ! = other.child :
140- return False
141- elif self .parent ! = other.parent:
142- return False
143- return self .value == other.value
123+ Additionally , it defines the __ne__() as stated in the
124+ documentation from python :
125+ By default , object implements __eq__() by using is , returning NotImplemented
126+ in the case of a false comparison: True if x is y else NotImplemented.
127+ For __ne__(), by default it delegates to __eq__() and inverts the result
128+ unless it is NotImplemented.
144129
145- elif op == 3 :
146- if (self .child != other.child or
147- self .parent != other.parent or self .value != other.value):
148- return True
149- else :
150- return False
130+ """
131+ if not isinstance(other , self.__class__ ):
132+ return False
151133
152- return NotImplemented
134+ if self .child != other.child:
135+ return False
136+ elif self .parent != other.parent:
137+ return False
138+ return self .value == other.value
153139
154140 def set_vector_idx (self , hyperparameter_to_idx: dict ):
155141 self .child_vector_id = hyperparameter_to_idx[self .child.name]
@@ -545,42 +531,6 @@ cdef class InCondition(AbstractCondition):
545531 self .value = values
546532 self .vector_values = [self .parent._inverse_transform(value) for value in self .values]
547533
548- def __richcmp__ (self , other: Any , int op ):
549- """
550- Todo: With Cython 2.7 this function can be replaced by using the six
551- Python special methods (__eq__(), __lt__(),...).
552- (--> https://cython.readthedocs.io/en/latest/src/userguide/special_methods.html\
553- #rich-comparisons)
554-
555- Before 2.7 there were no separate methods for the individual rich
556- comparison operations. Instead there is a single method __richcmp__()
557- which takes an integer indicating which operation is to be performed,
558- as follows:
559- < 0
560- == 2
561- > 4
562- <= 1
563- != 3
564- >= 5
565- """
566- if isinstance (other, self .__class__):
567-
568- if op == 2 :
569- if self .child != other.child:
570- return False
571- elif self .parent != other.parent:
572- return False
573- return self .values == other.values
574-
575- elif op == 3 :
576- if (self .child != other.child or
577- self .parent != other.parent or self .values != other.values):
578- return True
579- else :
580- return False
581-
582- return NotImplemented
583-
584534 def __repr__ (self ) -> str:
585535 return "%s | %s in {%s}" % (self.child.name , self.parent.name ,
586536 ", ".join(
@@ -618,47 +568,31 @@ cdef class AbstractConjunction(ConditionComponent):
618568 raise ValueError (" All Conjunctions and Conditions must have "
619569 " the same child." )
620570
621- def __richcmp__ (self , other: Any , int op ) :
571+ def __eq__ (self , other: Any ) -> bool :
622572 """
623- Todo: With Cython 2.7 this function can be replaced by using the six
624- Python special methods (__eq__(), __lt__(),...).
625- (--> https://cython.readthedocs.io/en/latest/src/userguide/special_methods.html\
626- #rich-comparisons)
627-
628- Before 2.7 there were no separate methods for the individual rich
629- comparison operations. Instead there is a single method __richcmp__()
630- which takes an integer indicating which operation is to be performed,
631- as follows:
632- < 0
633- == 2
634- > 4
635- <= 1
636- != 3
637- >= 5
573+ This method implements a comparison between self and another
574+ object.
575+
576+ Additionally , it defines the __ne__() as stated in the
577+ documentation from python:
578+ By default , object implements __eq__() by using is , returning NotImplemented
579+ in the case of a false comparison: True if x is y else NotImplemented.
580+ For __ne__(), by default it delegates to __eq__() and inverts the result
581+ unless it is NotImplemented.
582+
638583 """
639- if isinstance (other, self .__class__):
640- if len (self .components) != len (other.components):
641- if op == 2 :
642- return False
643- if op == 3 :
644- return True
645- else :
646- return NotImplemented
647-
648- for component, other_component in \
649- zip (self .components, other.components):
650- eq = component == other_component
651- if op == 2 :
652- if not eq:
653- return False
654- elif op == 3 :
655- if eq:
656- return False
657- else :
658- raise NotImplemented
659- return True
584+ if not isinstance(other , self.__class__ ):
585+ return False
586+
587+ if len (self .components) != len (other.components):
588+ return False
589+
590+ for component, other_component in zip (self .components, other.components):
591+ if (component != other_component):
592+ return False
593+
594+ return True
660595
661- return NotImplemented
662596
663597 def __copy__ (self ):
664598 return self .__class__ (* [copy.copy(comp) for comp in self .components])
0 commit comments