Use `inspect.signature` to try accessing `func` args. Otherwise, ensure they are provided by user.
(func, param_names)
| 1401 | |
| 1402 | |
| 1403 | def _get_func_args(func, param_names): |
| 1404 | """Use `inspect.signature` to try accessing `func` args. Otherwise, ensure |
| 1405 | they are provided by user. |
| 1406 | """ |
| 1407 | try: |
| 1408 | func_args = inspect.signature(func).parameters |
| 1409 | except ValueError as err: |
| 1410 | func_args = {} |
| 1411 | if not param_names: |
| 1412 | raise ValueError( |
| 1413 | "Unable to inspect `func` signature, and `param_names` was not provided." |
| 1414 | ) from err |
| 1415 | if param_names: |
| 1416 | params = param_names |
| 1417 | else: |
| 1418 | params = list(func_args)[1:] |
| 1419 | if any( |
| 1420 | (p.kind in [p.VAR_POSITIONAL, p.VAR_KEYWORD]) for p in func_args.values() |
| 1421 | ): |
| 1422 | raise ValueError( |
| 1423 | "`param_names` must be provided because `func` takes variable length arguments." |
| 1424 | ) |
| 1425 | return params, func_args |
nothing calls this directly
no test coverage detected
searching dependent graphs…