Add proper type hints to add_exception_handler#1308
Add proper type hints to add_exception_handler#1308phillipuniverse wants to merge 2 commits intoKludex:masterfrom
Conversation
|
I realized there are a lot of other callables in the |
Kludex
left a comment
There was a problem hiding this comment.
Yeah, PRs improving the type hints are welcome.
As for this PR, can we also add the type hint on the starlette/exceptions.py file as well (in the analogous signature)?
| self, | ||
| exc_class_or_status_code: typing.Union[int, typing.Type[Exception]], | ||
| handler: typing.Callable, | ||
| handler: typing.Callable[[Request, Exception], typing.Union[Response, typing.Coroutine[typing.Any, typing.Any, Response]]], |
There was a problem hiding this comment.
Should we perhaps use Awaitable instead? It looks better. 😗
| handler: typing.Callable[[Request, Exception], typing.Union[Response, typing.Coroutine[typing.Any, typing.Any, Response]]], | |
| handler: typing.Callable[[Request, Exception], typing.Union[Response, Awaitable[Response]]], |
|
@phillipuniverse Are you willing to address the changes requested? |
|
@aminalaee yes! Sorry, this fell off my radar a bit. I’ll get this back on track in the next couple of days. |
|
Thanks for the PR @phillipuniverse ! There's a discussion on #1456 about the idea we see here, so I'll close this PR. |
I lost a bit of time due to a missing return statement and type hint in an exception handler.
In my case I had registered an
HTTPExceptionexception handler without a return. Here's the exception I ended up with:Here's what my exception handler and registration looked like:
This is clearly an error but it would've been nice to get a type hint error on it before I went through and traced down the implementation.
Thanks for such a great library!