@@ -106,21 +106,19 @@ def url_path_for(
106106 route_path : str = route_info ["path" ]
107107 path_params : list [dict [str , str ]] = route_info ["path_params" ]
108108
109- # Validate the kwargs provided
110- for param , value in kwargs .items ():
111- # Check if the name is not a match
112- if param not in [p ["name" ] for p in path_params ] and path_params :
113- message = f"Unknown path parameter provided: { param } "
114- logger .error (message )
115- raise KeyError (message )
109+ # Validate the stored path params against the ones provided
110+ if path_params :
116111 for path_param in path_params :
117- if (
118- path_param ["name" ] == param
119- and type (value ).__name__ != path_param ["type" ]
120- ):
112+ param_name = path_param ["name" ]
113+ param_type = path_param ["type" ]
114+ if param_name not in kwargs .keys ():
115+ message = f"Path param { param_name !r} was not provided"
116+ logger .error (message )
117+ raise KeyError (message )
118+ if type (kwargs [param_name ]).__name__ != param_type :
121119 message = (
122- f"' { param } ' must be { path_param [ 'type' ] !r} ; "
123- f"received { type (value ).__name__ !r} "
120+ f"{ param_name !r } must be { param_type !r} ; "
121+ f"received { type (kwargs [ param_name ] ).__name__ !r} "
124122 )
125123 logger .error (message )
126124 raise TypeError (message )
@@ -132,7 +130,9 @@ def url_path_for(
132130if __name__ == "__main__" :
133131 # Run test on some existing routes
134132 url_path = url_path_for (
135- "bootstrap.pypi" ,
136- "get_pypi_index" ,
133+ "workflow.tomo_router" ,
134+ "register_tilt" ,
135+ visit_name = "nt15587-15" ,
136+ session_id = 2 ,
137137 )
138138 print (url_path )
0 commit comments