pyrit.common.get_kwarg_param#
- get_kwarg_param(*, kwargs: Dict[str, Any], param_name: str, expected_type: Type[_T], required: bool = True, default_value: _T | None = None) _T | None [source]#
Validate and extract a parameter from kwargs.
- Parameters:
kwargs (Dict[str, Any]) – The dictionary containing parameters.
param_name (str) – The name of the parameter to validate.
expected_type (Type[_T]) – The expected type of the parameter.
required (bool) – Whether the parameter is required. If True, raises ValueError if missing.
default_value (Optional[_T]) – Default value to return if the parameter is not required and not present.
kwargs – The dictionary containing parameters.
param_name – The name of the parameter to validate.
expected_type – The expected type of the parameter.
required – Whether the parameter is required. If True, raises ValueError if missing.
default_value – Default value to return if the parameter is not required and not present.
- Returns:
The validated parameter value if present and valid, otherwise None.
- Return type:
Optional[_T]
- Returns:
The validated parameter value if present and valid, otherwise None.
- Return type:
Optional[_T]
- Raises:
ValueError – If the parameter is missing or None.
TypeError – If the parameter is not of the expected type.