@@ -130,14 +130,14 @@ public static NewReference tp_richcompare(BorrowedReference ob, BorrowedReferenc
130130 return new NewReference ( pytrue ) ;
131131 }
132132
133- GetSecondCompareOperandInstance ( ob , other , out co1 , out co2 , out co1Inst , out co2Inst , out error ) ;
133+ TryGetSecondCompareOperandInstance ( ob , other , out co1 , out co2Inst ) ;
134134
135135 if ( co2Inst == null )
136136 {
137137 return new NewReference ( pyfalse ) ;
138138 }
139139
140- if ( Equals ( co1Inst , co2Inst ) )
140+ if ( Equals ( co1 . inst , co2Inst ) )
141141 {
142142 return new NewReference ( pytrue ) ;
143143 }
@@ -147,14 +147,12 @@ public static NewReference tp_richcompare(BorrowedReference ob, BorrowedReferenc
147147 case Runtime . Py_LE :
148148 case Runtime . Py_GT :
149149 case Runtime . Py_GE :
150- GetSecondCompareOperandInstance ( ob , other , out co1 , out co2 , out co1Inst , out co2Inst , out error ) ;
151-
152- if ( ! error . IsNone ( ) && ! error . IsNull ( ) )
150+ if ( ! TryGetSecondCompareOperandInstance ( ob , other , out co1 , out co2Inst ) )
153151 {
154152 return Exceptions . RaiseTypeError ( "Cannot get managed object" ) ;
155153 }
156154
157- var co1Comp = co1Inst as IComparable ;
155+ var co1Comp = co1 . inst as IComparable ;
158156 if ( co1Comp == null )
159157 {
160158 Type co1Type = co1 . GetType ( ) ;
@@ -209,17 +207,18 @@ public static NewReference tp_richcompare(BorrowedReference ob, BorrowedReferenc
209207 }
210208 }
211209
212- private static void GetSecondCompareOperandInstance ( BorrowedReference left , BorrowedReference right ,
213- out CLRObject co1 , out CLRObject co2 , out object co1Inst , out object co2Inst , out NewReference error )
210+ private static bool TryGetSecondCompareOperandInstance ( BorrowedReference left , BorrowedReference right , out CLRObject co1 , out object co2Inst )
214211 {
215- co1Inst = null ;
216212 co2Inst = null ;
217- error = new NewReference ( Runtime . PyNone ) ;
218213
219214 co1 = ( CLRObject ) GetManagedObject ( left ) ! ;
220- co2 = GetManagedObject ( right ) as CLRObject ;
215+ if ( co1 == null )
216+ {
217+ return false ;
218+ }
219+
220+ var co2 = GetManagedObject ( right ) as CLRObject ;
221221
222- var co2IsValid = true ;
223222 // The object comparing against is not a managed object. It could still be a Python object
224223 // that can be compared against (e.g. comparing against a Python string)
225224 if ( co2 == null )
@@ -230,28 +229,14 @@ private static void GetSecondCompareOperandInstance(BorrowedReference left, Borr
230229 if ( Converter . ToManagedValue ( pyCo2 , typeof ( object ) , out var result , false ) )
231230 {
232231 co2Inst = result ;
232+ return true ;
233233 }
234- else
235- {
236- co2IsValid = false ;
237- }
238- }
239- else
240- {
241- co2IsValid = false ;
242234 }
243- }
244- else
245- {
246- co2Inst = co2 . inst ;
247- }
248-
249- if ( co1 == null || ! co2IsValid )
250- {
251- error = Exceptions . RaiseTypeError ( "Cannot get managed object" ) ;
235+ return false ;
252236 }
253237
254- co1Inst = co1 . inst ;
238+ co2Inst = co2 . inst ;
239+ return true ;
255240 }
256241
257242 /// <summary>
0 commit comments