File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -381,11 +381,12 @@ STATIC const qstr binary_op_method_name[] = {
381381 MP_BINARY_OP_INPLACE_MODULO,
382382 MP_BINARY_OP_INPLACE_POWER,*/
383383 [MP_BINARY_OP_LESS ] = MP_QSTR___lt__ ,
384- /*MP_BINARY_OP_MORE,
385- MP_BINARY_OP_EQUAL,
386- MP_BINARY_OP_LESS_EQUAL,
387- MP_BINARY_OP_MORE_EQUAL,
388- MP_BINARY_OP_NOT_EQUAL,
384+ [MP_BINARY_OP_MORE ] = MP_QSTR___gt__ ,
385+ [MP_BINARY_OP_EQUAL ] = MP_QSTR___eq__ ,
386+ [MP_BINARY_OP_LESS_EQUAL ] = MP_QSTR___le__ ,
387+ [MP_BINARY_OP_MORE_EQUAL ] = MP_QSTR___ge__ ,
388+ /*
389+ MP_BINARY_OP_NOT_EQUAL, // a != b calls a == b and inverts result
389390 */
390391 [MP_BINARY_OP_IN ] = MP_QSTR___contains__ ,
391392 /*
Original file line number Diff line number Diff line change @@ -64,6 +64,10 @@ Q(__getattr__)
6464Q (__del__ )
6565Q (__call__ )
6666Q (__lt__ )
67+ Q (__gt__ )
68+ Q (__eq__ )
69+ Q (__le__ )
70+ Q (__ge__ )
6771
6872Q (micropython )
6973Q (bytecode )
Original file line number Diff line number Diff line change 1+ class foo (object ):
2+ def __init__ (self , value ):
3+ self .x = value
4+
5+ def __eq__ (self , other ):
6+ print ('eq' )
7+ return self .x == other .x
8+
9+ def __lt__ (self , other ):
10+ print ('lt' )
11+ return self .x < other .x
12+
13+ def __gt__ (self , other ):
14+ print ('gt' )
15+ return self .x > other .x
16+
17+ def __le__ (self , other ):
18+ print ('le' )
19+ return self .x <= other .x
20+
21+ def __ge__ (self , other ):
22+ print ('ge' )
23+ return self .x >= other .x
24+
25+ for i in range (3 ):
26+ for j in range (3 ):
27+ print (foo (i ) == foo (j ))
28+ print (foo (i ) < foo (j ))
29+ print (foo (i ) > foo (j ))
30+ print (foo (i ) <= foo (j ))
31+ print (foo (i ) >= foo (j ))
You can’t perform that action at this time.
0 commit comments