@@ -943,7 +943,8 @@ pub fn definitions_for_bin_op<'db>(
943943 return None ;
944944 } ;
945945
946- let callable_type = bindings. callable_type ( ) ;
946+ let callable_type = promote_literals_for_self ( db, bindings. callable_type ( ) ) ;
947+
947948 let definitions: Vec < _ > = bindings
948949 . into_iter ( )
949950 . flat_map ( std:: iter:: IntoIterator :: into_iter)
@@ -981,7 +982,7 @@ pub fn definitions_for_unary_op<'db>(
981982 return None ;
982983 } ;
983984
984- let callable_type = bindings. callable_type ( ) ;
985+ let callable_type = promote_literals_for_self ( db , bindings. callable_type ( ) ) ;
985986
986987 let definitions = bindings
987988 . into_iter ( )
@@ -996,6 +997,24 @@ pub fn definitions_for_unary_op<'db>(
996997 Some ( ( definitions, callable_type) )
997998}
998999
1000+ /// Promotes literal types in `self` positions to their fallback instance types.
1001+ ///
1002+ /// This is so that we show `int.__add__` instead of `IntLiteral.__add__`.
1003+ fn promote_literals_for_self < ' db > ( db : & ' db dyn Db , ty : Type < ' db > ) -> Type < ' db > {
1004+ match ty {
1005+ Type :: BoundMethod ( method) => Type :: BoundMethod ( method. map_self_type ( db, |self_ty| {
1006+ self_ty. literal_fallback_instance ( db) . unwrap_or ( self_ty)
1007+ } ) ) ,
1008+ Type :: Union ( elements) => elements. map ( db, |ty| match ty {
1009+ Type :: BoundMethod ( method) => Type :: BoundMethod ( method. map_self_type ( db, |self_ty| {
1010+ self_ty. literal_fallback_instance ( db) . unwrap_or ( self_ty)
1011+ } ) ) ,
1012+ _ => * ty,
1013+ } ) ,
1014+ ty => ty,
1015+ }
1016+ }
1017+
9991018/// Find the active signature index from `CallSignatureDetails`.
10001019/// The active signature is the first signature where all arguments present in the call
10011020/// have valid mappings to parameters (i.e., none of the mappings are None).
0 commit comments