@@ -857,43 +857,6 @@ fn binding_accepts_keyword(params: &[Param], name: &Wtf8) -> bool {
857857 } )
858858}
859859
860- /// First positional-or-keyword parameter that was also passed by keyword.
861- fn duplicate_name_and_position < ' a > (
862- params : & ' a [ Param ] ,
863- nargs : usize ,
864- kwargs : & KwArgs ,
865- ) -> Option < ( & ' a str , usize ) > {
866- fn walk < ' a > (
867- params : & ' a [ Param ] ,
868- nargs : usize ,
869- kwargs : & KwArgs ,
870- pos : & mut usize ,
871- ) -> Option < ( & ' a str , usize ) > {
872- for param in params {
873- match param. kind {
874- ParamKind :: Flatten ( Some ( inner) ) => {
875- if let Some ( hit) = walk ( inner, nargs, kwargs, pos) {
876- return Some ( hit) ;
877- }
878- }
879- ParamKind :: Flatten ( None ) | ParamKind :: PositionalOnly => {
880- * pos += 1 ;
881- }
882- ParamKind :: PositionalOrKeyword => {
883- * pos += 1 ;
884- if nargs >= * pos && !param. name . is_empty ( ) && kwargs. contains_key ( param. name ) {
885- return Some ( ( param. name , * pos) ) ;
886- }
887- }
888- ParamKind :: VarPositional => return None ,
889- ParamKind :: KeywordOnly | ParamKind :: VarKeyword => { }
890- }
891- }
892- None
893- }
894- walk ( params, nargs, kwargs, & mut 0 )
895- }
896-
897860/// Walk `params` in declaration order looking for the first required argument
898861/// that is missing. `Err(None)` ends the walk without a result.
899862fn missing_from_params (
@@ -1152,7 +1115,7 @@ pub trait FromArgs: Sized {
11521115
11531116 /// Validate a known binding shape before converting any argument, following
11541117 /// `_PyArg_UnpackKeywords` error ordering. Explicit custom parsers keep the
1155- /// conservative positional-count, duplicate, and missing-argument checks.
1118+ /// positional-count and no-keyword checks, but own named validation .
11561119 /// Invalid known parameter ordering is rejected at compile time.
11571120 ///
11581121 /// The missing-argument walk is skipped when every required positional
@@ -1204,21 +1167,6 @@ pub trait FromArgs: Sized {
12041167 if Self :: TAKES_NO_KEYWORDS && num_given < * arity. start ( ) {
12051168 return Some ( ArgumentError :: TooFewArgs . into_exception ( arity, num_given, 0 , callee, vm) ) ;
12061169 }
1207- if let Some ( params) = Self :: PARAMS
1208- && !args. kwargs . is_empty ( )
1209- && let Some ( ( name, pos) ) = duplicate_name_and_position ( params, num_given, & args. kwargs )
1210- {
1211- return Some ( callee. given_by_name_and_position ( name, pos, vm) ) ;
1212- }
1213- if num_given < * arity. start ( ) || const { Self :: HAS_REQUIRED_KEYWORD_ONLY } {
1214- let mut pos = 0 ;
1215- let mut skip = instance;
1216- if let Err ( Some ( missing) ) =
1217- Self :: missing_from ( num_given, & args. kwargs , & mut pos, & mut skip)
1218- {
1219- return Some ( missing. into_exception ( arity, num_given, 0 , callee, vm) ) ;
1220- }
1221- }
12221170 None
12231171 }
12241172
@@ -1881,6 +1829,13 @@ mod tests {
18811829 second : i32 ,
18821830 }
18831831
1832+ #[ allow( dead_code) ]
1833+ #[ derive( FromArgs ) ]
1834+ struct FlattenedLegacy {
1835+ #[ pyarg( flatten) ]
1836+ args : ( PyObjectRef , LegacyNamed ) ,
1837+ }
1838+
18841839 struct DisplayOnly ( FuncArgs ) ;
18851840
18861841 impl FromArgs for DisplayOnly {
@@ -2025,6 +1980,21 @@ mod tests {
20251980 } ) ;
20261981 }
20271982
1983+ #[ test]
1984+ fn legacy_conversion_order_survives_receivers_and_flattened_composition ( ) {
1985+ crate :: Interpreter :: without_stdlib ( Default :: default ( ) ) . enter ( |vm| {
1986+ for message in [
1987+ binding_error :: < ( PyObjectRef , LegacyNamed ) > ( 2 , & [ ] , true , vm) ,
1988+ binding_error :: < FlattenedLegacy > ( 2 , & [ ] , true , vm) ,
1989+ binding_error :: < ( LegacyNamed , ( ) ) > ( 1 , & [ "first" ] , false , vm) ,
1990+ ] {
1991+ assert ! ( message. contains( "NoneType" ) , "{message}" ) ;
1992+ assert ! ( !message. contains( "missing required" ) , "{message}" ) ;
1993+ assert ! ( !message. contains( "given by name" ) , "{message}" ) ;
1994+ }
1995+ } ) ;
1996+ }
1997+
20281998 #[ test]
20291999 fn explicitly_custom_signatures_do_not_opt_in_to_clinic_validation ( ) {
20302000 const { assert ! ( DisplayOnly :: BINDING_PARAMS . is_none( ) ) } ;
0 commit comments