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

Fix authentication.requires type #1659

Merged
merged 5 commits into from
Jun 11, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions starlette/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from starlette.responses import RedirectResponse, Response
from starlette.websockets import WebSocket

_CallableType = typing.TypeVar("_CallableType", bound=typing.Callable)


def has_required_scope(conn: HTTPConnection, scopes: typing.Sequence[str]) -> bool:
for scope in scopes:
Expand All @@ -21,7 +23,7 @@ def requires(
scopes: typing.Union[str, typing.Sequence[str]],
status_code: int = 403,
redirect: typing.Optional[str] = None,
) -> typing.Callable:
) -> typing.Callable[[_CallableType], _CallableType]:
scopes_list = [scopes] if isinstance(scopes, str) else list(scopes)

def decorator(func: typing.Callable) -> typing.Callable:
Expand Down Expand Up @@ -95,7 +97,7 @@ def sync_wrapper(*args: typing.Any, **kwargs: typing.Any) -> Response:

return sync_wrapper

return decorator
return decorator # type: ignore
Copy link
Sponsor Member

@Kludex Kludex Jun 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add at least the error on ignore[<error>]? 🙏

adriangb marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return decorator # type: ignore
return decorator # type: ignore[return-value] # type checkers can't verify the type of the wrapper

Copy link
Sponsor Member

@Kludex Kludex Jun 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm already happy with just the return-value thingy, no need the comment stuff



class AuthenticationError(Exception):
Expand Down