You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add ParamSpec to legacy callable forms of raises/warns/deprecated_call
`pytest.raises`, `warns` & `deprecated_call` previously typed `*args`
and `**kwargs` as `Any` in the legacy callable form, so this did not
raise errors:
```py
def foo(x: int) -> None:
raise ValueError
raises(ValueError, foo, None)
```
but now it will give call-overload.
It also makes it possible to pass `func` as a kwarg, which the type
hints previously showed as possible, but it didn't work.
It's possible that `func` (and the expected type?) should be pos-only,
as this looks quite weird:
```py
raises(1, 2, kwarg1=3, func=my_func, kwarg2=4, expected_exception=ValueError)
```
but if somebody is dynamically generating parameters to send to `raises`
then we probably shouldn't ban it needlessly; and we can't make `func`
pos-only without making `expected_exception` pos-only, and that could
break backwards compatibility.
:func:`pytest.raises`, :func:`pytest.warns` and :func:`pytest.deprecated_call` now uses :class:`ParamSpec` for the type hint to the (old and not recommended) callable overload, instead of :class:`Any`. This allows type checkers to raise errors when passing incorrect function parameters.
2
+
``func`` can now also be passed as a kwarg, which the type hint previously showed as possible but didn't accept.
0 commit comments