-
-
Notifications
You must be signed in to change notification settings - Fork 949
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix exception_handlers
type hints
#1360
Conversation
change type hints in ExceptionMiddleware
b6cf47e
to
42902fb
Compare
app: ASGIApp, | ||
handlers: typing.Mapping[ | ||
typing.Any, typing.Callable[[Request, Exception], Response] | ||
] = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's quite a complicated type, should we move it to starlette.types
? Like ExceptionHandler
type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current types on types.py
are going to be removed at some point: #1217
That file will only contain this type at some point. Is that a problem? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't notice the Issue,
This mapping type just seems a bit complicated to me to be copied multiple times
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One drawback I noticed in VScode, haven't really checked and there might be some workarounds, is that they don't show function signatures when using the aliases as you mention. Not sure if it happens on PyCharm and other tools.
Speaking about |
@aminalaee @k4black FYI, I've opened a PR that improves on the typing added in this PR: #1456 |
Closes #1142 and replaces #1139.
Changes
exception_handlers
type hints:I also changed the callable type hints, I think it makes sense to be more explicit, this will catch user-defined callable mismatches (?).
As mentioned in #1139 we can't use
typing.Mapping[typing.Union[int, ..], ...]
since dict keys are not covariant.I think we could use.typing.TypedDict
but only after 3.8