Skip to content
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

Improve typing for errorhandler decorator. #4095

Closed
pcorpet opened this issue May 21, 2021 · 1 comment
Closed

Improve typing for errorhandler decorator. #4095

pcorpet opened this issue May 21, 2021 · 1 comment
Labels
Milestone

Comments

@pcorpet
Copy link
Contributor

pcorpet commented May 21, 2021

Today the errorhandler decorator does not have consistency between the type of error in its parameter and the parameter of the function it is wrapping although those should be the same.

The following code should be properly typed:

@app.errorhandler(auth.ExpiredTokenException)
def expired_token(error: auth.ExpiredTokenException) -> Tuple[str, int]:
    """Handle the 498 error."""

    return error.description or i18n.flask_translate("Expired token"), 498

the current version enforces it to be typed as

@app.errorhandler(auth.ExpiredTokenException)
def expired_token(untyped_error: Exception) -> Tuple[str, int]:
    """Handle the 498 error."""

    error = typing.cast(auth.ExpiredTokenException, untyped_error)
    return error.description or i18n.flask_translate("Expired token"), 498
@davidism davidism added this to the 2.0.2 milestone Jun 5, 2021
@davidism davidism closed this as completed Jun 5, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 20, 2021
@davidism
Copy link
Member

In #4487, I relaxed the type for the callable argument to Any.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
@davidism @pcorpet and others