@@ -17,7 +17,10 @@ use super::obj::objlist;
1717use super :: obj:: objobject;
1818use super :: obj:: objtuple;
1919use super :: obj:: objtype;
20- use super :: pyobject:: { DictProtocol , PyContext , PyFuncArgs , PyObjectKind , PyObjectRef , PyResult } ;
20+ use super :: pyobject:: {
21+ AttributeProtocol , DictProtocol , PyContext , PyFuncArgs , PyObjectKind , PyObjectRef , PyResult ,
22+ TypeProtocol ,
23+ } ;
2124use super :: stdlib;
2225use super :: sysmodule;
2326
@@ -375,7 +378,20 @@ impl VirtualMachine {
375378}
376379
377380pub fn _sub ( & mut self , a : PyObjectRef , b : PyObjectRef ) ->PyResult {
378- self . call_method ( & a, "__sub__" , vec ! [ b] )
381+ // Try __sub__, next __rsub__, next, give up
382+ if a. has_attr ( "__sub__" ) {
383+ self . call_method ( & a, "__sub__" , vec ! [ b] )
384+ } else if b. has_attr ( "__rsub__" ) {
385+ self . call_method ( & b, "__rsub__" , vec ! [ a] )
386+ } else {
387+ // Cannot sub a and b
388+ let a_type_name = objtype:: get_type_name ( & a. typ ( ) ) ;
389+ let b_type_name = objtype:: get_type_name ( & b. typ ( ) ) ;
390+ Err ( self . new_type_error ( format ! (
391+ "Unsupported operand types for '-': '{}' and '{}'" ,
392+ a_type_name, b_type_name
393+ ) ) )
394+ }
379395}
380396
381397pub fn _add ( & mut self , a : PyObjectRef , b : PyObjectRef ) ->PyResult {