(*args, **kwargs)
| 186 | |
| 187 | @functools.wraps(func) |
| 188 | def wrapper(*args, **kwargs): |
| 189 | global_skip_validation = get_config()["skip_parameter_validation"] |
| 190 | if global_skip_validation: |
| 191 | return func(*args, **kwargs) |
| 192 | |
| 193 | func_sig = signature(func) |
| 194 | |
| 195 | # Map *args/**kwargs to the function signature |
| 196 | params = func_sig.bind(*args, **kwargs) |
| 197 | params.apply_defaults() |
| 198 | |
| 199 | # ignore self/cls and positional/keyword markers |
| 200 | to_ignore = [ |
| 201 | p.name |
| 202 | for p in func_sig.parameters.values() |
| 203 | if p.kind in (p.VAR_POSITIONAL, p.VAR_KEYWORD) |
| 204 | ] |
| 205 | to_ignore += ["self", "cls"] |
| 206 | params = {k: v for k, v in params.arguments.items() if k not in to_ignore} |
| 207 | |
| 208 | validate_parameter_constraints( |
| 209 | parameter_constraints, params, caller_name=func.__qualname__ |
| 210 | ) |
| 211 | |
| 212 | try: |
| 213 | with config_context( |
| 214 | skip_parameter_validation=( |
| 215 | prefer_skip_nested_validation or global_skip_validation |
| 216 | ) |
| 217 | ): |
| 218 | return func(*args, **kwargs) |
| 219 | except InvalidParameterError as e: |
| 220 | # When the function is just a wrapper around an estimator, we allow |
| 221 | # the function to delegate validation to the estimator, but we replace |
| 222 | # the name of the estimator by the name of the function in the error |
| 223 | # message to avoid confusion. |
| 224 | msg = re.sub( |
| 225 | r"parameter of \w+ must be", |
| 226 | f"parameter of {func.__qualname__} must be", |
| 227 | str(e), |
| 228 | ) |
| 229 | raise InvalidParameterError(msg) from e |
| 230 | |
| 231 | return wrapper |
| 232 |
nothing calls this directly
no test coverage detected
searching dependent graphs…