Skip to content

Commit

Permalink
(#1164) Type annotate auth.py (#1185)
Browse files Browse the repository at this point in the history
(#1164) Type annotate auth.py
  • Loading branch information
PythonCoderAS authored and bboe committed Dec 29, 2019
1 parent d516353 commit 57990c6
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions praw/models/auth.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Provide the Auth class."""
from typing import Dict, List, NoReturn, Optional, Set, Union

from prawcore import (
Authorizer,
ImplicitAuthorizer,
Expand All @@ -14,7 +16,7 @@ class Auth(PRAWBase):
"""Auth provides an interface to Reddit's authorization."""

@property
def limits(self):
def limits(self) -> Dict[str, Optional[Union[str, int]]]:
"""Return a dictionary containing the rate limit info.
The keys are:
Expand Down Expand Up @@ -42,7 +44,7 @@ def limits(self):
"used": data.used,
}

def authorize(self, code):
def authorize(self, code: str) -> Optional[str]:
"""Complete the web authorization flow and return the refresh token.
:param code: The code obtained through the request to the redirect uri.
Expand All @@ -58,7 +60,9 @@ def authorize(self, code):
self._reddit._core = self._reddit._authorized_core = authorized_session
return authorizer.refresh_token

def implicit(self, access_token, expires_in, scope):
def implicit(
self, access_token: str, expires_in: int, scope: str
) -> NoReturn:
"""Set the active authorization to be an implicit authorization.
:param access_token: The access_token obtained from Reddit's callback.
Expand All @@ -84,7 +88,7 @@ def implicit(self, access_token, expires_in, scope):
)
self._reddit._core = self._reddit._authorized_core = implicit_session

def scopes(self):
def scopes(self) -> Set[str]:
"""Return a set of scopes included in the current authorization.
For read-only authorizations this should return ``{'*'}``.
Expand All @@ -95,7 +99,13 @@ def scopes(self):
authorizer.refresh()
return authorizer.scopes

def url(self, scopes, state, duration="permanent", implicit=False):
def url(
self,
scopes: List[str],
state: str,
duration: str = "permanent",
implicit: bool = False,
) -> str:
"""Return the URL used out-of-band to grant access to your application.
:param scopes: A list of OAuth scopes to request authorization for.
Expand Down

0 comments on commit 57990c6

Please sign in to comment.