@@ -4,7 +4,7 @@ use pyo3::intern;
44use pyo3:: prelude:: * ;
55use pyo3:: types:: { PyDict , PyList , PyString , PyTuple } ;
66
7- use ahash:: { AHashSet , AHashMap } ;
7+ use ahash:: AHashSet ;
88use pyo3:: IntoPyObjectExt ;
99
1010use crate :: build_tools:: py_schema_err;
@@ -45,7 +45,7 @@ struct Parameter {
4545 kwarg_key : Option < Py < PyString > > ,
4646 validator : CombinedValidator ,
4747 alias : Option < Py < PyAny > > ,
48- mode : String
48+ mode : String ,
4949}
5050
5151#[ derive( Debug ) ]
@@ -98,9 +98,10 @@ impl BuildValidator for ArgumentsValidator {
9898 had_keyword_only = true ;
9999 }
100100
101- let kwarg_key = match mode == "keyword_only" || mode == "positional_or_keyword" {
102- true => Some ( py_name. unbind ( ) ) ,
103- false => None ,
101+ let kwarg_key = if mode == "keyword_only" || mode == "positional_or_keyword" {
102+ Some ( py_name. unbind ( ) )
103+ } else {
104+ None
104105 } ;
105106
106107 let schema = arg. get_as_req ( intern ! ( py, "schema" ) ) ?;
@@ -130,8 +131,8 @@ impl BuildValidator for ArgumentsValidator {
130131 name,
131132 kwarg_key,
132133 validator,
133- alias : arg. get_item ( intern ! ( py, "alias" ) ) ?. map ( |v| v . into ( ) ) ,
134- mode : mode. to_string ( )
134+ alias : arg. get_item ( intern ! ( py, "alias" ) ) ?. map ( std :: convert :: Into :: into) ,
135+ mode : mode. to_string ( ) ,
135136 } ) ;
136137 }
137138
@@ -192,20 +193,11 @@ impl Validator for ArgumentsValidator {
192193 let mut output_args: Vec < PyObject > = Vec :: with_capacity ( self . positional_params_count ) ;
193194 let output_kwargs = PyDict :: new ( py) ;
194195 let mut errors: Vec < ValLineError > = Vec :: new ( ) ;
195- let mut used_kwargs: AHashSet < & str > = AHashSet :: with_capacity ( self . parameters . len ( ) ) ;
196+ let mut used_kwargs: AHashSet < String > = AHashSet :: with_capacity ( self . parameters . len ( ) ) ;
196197
197198 let validate_by_alias = state. validate_by_alias_or ( self . validate_by_alias ) ;
198199 let validate_by_name = state. validate_by_name_or ( self . validate_by_name ) ;
199200
200- let mut lookup_keys = AHashMap :: with_capacity ( self . parameters . len ( ) ) ;
201- for param in & self . parameters {
202- if param. mode == "keyword_only" || param. mode == "positional_or_keyword" {
203- let param_name = param. name . as_str ( ) ;
204- let lookup_key = get_lookup_key ( py, & param. alias , validate_by_name, validate_by_alias, param_name) ?;
205- lookup_keys. insert ( param_name, lookup_key) ;
206- }
207- }
208-
209201 // go through arguments getting the value from args or kwargs and validating it
210202 for ( index, parameter) in self . parameters . iter ( ) . enumerate ( ) {
211203 let mut pos_value = None ;
@@ -215,12 +207,21 @@ impl Validator for ArgumentsValidator {
215207 }
216208 }
217209 let mut kw_value = None ;
218- let kw_lookup_key = lookup_keys. get ( parameter. name . as_str ( ) ) ;
210+ let mut kw_lookup_key = None ;
211+ if parameter. mode == "keyword_only" || parameter. mode == "positional_or_keyword" {
212+ kw_lookup_key = Some ( get_lookup_key (
213+ py,
214+ parameter. alias . as_ref ( ) ,
215+ validate_by_name,
216+ validate_by_alias,
217+ & parameter. name ,
218+ ) ?) ;
219+ }
219220
220221 if let Some ( kwargs) = args. kwargs ( ) {
221- if let Some ( lookup_key) = kw_lookup_key {
222+ if let Some ( ref lookup_key) = kw_lookup_key {
222223 if let Some ( ( lookup_path, value) ) = kwargs. get_item ( lookup_key) ? {
223- used_kwargs. insert ( lookup_path. first_key ( ) ) ;
224+ used_kwargs. insert ( lookup_path. first_key ( ) . to_string ( ) ) ;
224225 kw_value = Some ( ( lookup_path, value) ) ;
225226 }
226227 }
0 commit comments