Ensure that a wrapper has the same signature as the wrapped function. This is used to guarantee that a TypeError raised due to a bad API call is raised consistently (using variadic signatures would hide such errors).
(wrapper, wrapped)
| 538 | |
| 539 | |
| 540 | def _ensure_wrapper_signature(wrapper, wrapped): |
| 541 | """Ensure that a wrapper has the same signature as the wrapped function. |
| 542 | |
| 543 | This is used to guarantee that a TypeError raised due to a bad API call |
| 544 | is raised consistently (using variadic signatures would hide such errors). |
| 545 | """ |
| 546 | try: |
| 547 | wrapped_sig = inspect.signature(wrapped) |
| 548 | except ValueError: # built-in signature cannot be found |
| 549 | return |
| 550 | |
| 551 | wrapper_sig = inspect.signature(wrapper) |
| 552 | if wrapped_sig != wrapper_sig: |
| 553 | fullname = f"{wrapped.__module__}.{wrapped.__qualname__}" |
| 554 | raise AssertionError( |
| 555 | f"signature for {fullname}() is incorrect:\n" |
| 556 | f" expect: {wrapped_sig}\n" |
| 557 | f" actual: {wrapper_sig}" |
| 558 | ) |
| 559 | |
| 560 | |
| 561 | def _make_conditional_decorator(test, /, *test_args, **test_kwargs): |
no test coverage detected
searching dependent graphs…