@@ -12,9 +12,10 @@ use ruff_db::parsed::parsed_module;
1212use smallvec:: { SmallVec , smallvec, smallvec_inline} ;
1313
1414use super :: { Argument , CallArguments , CallError , CallErrorKind , InferContext , Signature , Type } ;
15+ use crate :: Program ;
1516use crate :: db:: Db ;
1617use crate :: dunder_all:: dunder_all_names;
17- use crate :: place:: { Boundness , Place } ;
18+ use crate :: place:: { Boundness , Place , PlaceAndQualifiers } ;
1819use crate :: types:: diagnostic:: {
1920 CALL_NON_CALLABLE , CONFLICTING_ARGUMENT_FORMS , INVALID_ARGUMENT_TYPE , MISSING_ARGUMENT ,
2021 NO_MATCHING_OVERLOAD , PARAMETER_ALREADY_ASSIGNED , TOO_MANY_POSITIONAL_ARGUMENTS ,
@@ -29,11 +30,11 @@ use crate::types::signatures::{Parameter, ParameterForm, Parameters};
2930use crate :: types:: tuple:: { Tuple , TupleLength , TupleType } ;
3031use crate :: types:: {
3132 BoundMethodType , ClassLiteral , DataclassParams , FieldInstance , KnownClass , KnownInstanceType ,
32- MethodWrapperKind , PropertyInstanceType , SpecialFormType , TypeMapping , UnionType ,
33- WrapperDescriptorKind , enums, ide_support, todo_type,
33+ MemberLookupPolicy , MethodWrapperKind , PropertyInstanceType , SpecialFormType , TypeMapping ,
34+ UnionType , WrapperDescriptorKind , enums, ide_support, todo_type,
3435} ;
3536use ruff_db:: diagnostic:: { Annotation , Diagnostic , SubDiagnostic , SubDiagnosticSeverity } ;
36- use ruff_python_ast as ast;
37+ use ruff_python_ast:: { self as ast, PythonVersion } ;
3738
3839/// Binding information for a possible union of callables. At a call site, the arguments must be
3940/// compatible with _all_ of the types in the union for the call to be valid.
@@ -948,6 +949,37 @@ impl<'db> Bindings<'db> {
948949 }
949950 }
950951
952+ Some ( KnownFunction :: Replace )
953+ if Program :: get ( db) . python_version ( db) >= PythonVersion :: PY313 =>
954+ {
955+ let [ Some ( instance_ty) , _] = overload. parameter_types ( ) else {
956+ continue ;
957+ } ;
958+ let PlaceAndQualifiers {
959+ place : Place :: Type ( Type :: Callable ( attr_ty) , _) ,
960+ qualifiers : _,
961+ } = instance_ty. class_member_with_policy (
962+ db,
963+ "__replace__" . into ( ) ,
964+ MemberLookupPolicy :: MRO_NO_OBJECT_FALLBACK ,
965+ )
966+ else {
967+ continue ;
968+ } ;
969+ let Some (
970+ _signature @ Signature {
971+ return_ty : Some ( return_ty) ,
972+ ..
973+ } ,
974+ ) = attr_ty. signatures ( db) . overloads . first ( )
975+ else {
976+ continue ;
977+ } ;
978+ // TODO(thejchap): set param types on overload
979+ // println!("params: {:?}", signature.parameters());
980+ overload. set_return_type ( * return_ty) ;
981+ }
982+
951983 _ => {
952984 // Ideally, either the implementation, or exactly one of the overloads
953985 // of the function can have the dataclass_transform decorator applied.
0 commit comments