Return true if function accepts arbitrary keyword arguments.
(fun)
| 398 | |
| 399 | |
| 400 | def fun_accepts_kwargs(fun): |
| 401 | """Return true if function accepts arbitrary keyword arguments.""" |
| 402 | # inspect.signature evaluates annotations in Python 3.14+ (PEP 649), |
| 403 | # which raises NameError for types only imported under TYPE_CHECKING. |
| 404 | # Check co_flags directly to avoid touching annotations entirely. |
| 405 | code = getattr(fun, '__code__', None) |
| 406 | if code is not None: |
| 407 | return bool(code.co_flags & inspect.CO_VARKEYWORDS) |
| 408 | return any( |
| 409 | p for p in inspect.signature(fun).parameters.values() |
| 410 | if p.kind == p.VAR_KEYWORD |
| 411 | ) |
| 412 | |
| 413 | |
| 414 | def maybe(typ, val): |