-
Notifications
You must be signed in to change notification settings - Fork 307
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: add type hints to credentials #1605
base: main
Are you sure you want to change the base?
Conversation
|
||
from google.auth import _helpers | ||
|
||
|
||
class _BaseCredentials(metaclass=abc.ABCMeta): | ||
class BaseCredentials(metaclass=abc.ABCMeta): |
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.
Why do we want to change this to a public class?
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.
_BaseCredentials
is imported from outside the _credentials_base.py
file, so it's not private in that scope. You can see that it's captured as an error by running:
pyright google/auth/credentials.py
@@ -62,7 +63,7 @@ def refresh(self, request): | |||
# (pylint doesn't recognize that this is abstract) | |||
raise NotImplementedError("Refresh must be implemented") | |||
|
|||
def _apply(self, headers, token=None): | |||
def _apply(self, headers: dict[str, str], token: Optional[str] = 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.
Shall we use Mapping
from typing (here and in other places)? Also update the docstring to Mapping[str, str]
.
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.
This operation requires the type of headers
has __setitem__
method that's why being a Mapping
is not enough:
headers["authorization"] = "Bearer {}".format(
_helpers.from_bytes(token or self.token)
)
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.
Do you want me to modify the doctring instead?
google/auth/_refresh_worker.py
Outdated
@@ -32,7 +34,7 @@ def __init__(self): | |||
self._worker = None | |||
self._lock = threading.Lock() # protects access to worker threads. | |||
|
|||
def start_refresh(self, cred, request): | |||
def start_refresh(self, cred: Credentials, request: Request): |
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.
def start_refresh(self, cred: Credentials, request: Request): | |
def start_refresh(self, cred: Credentials, request: Request): -> bool |
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.
done
google/auth/_refresh_worker.py
Outdated
@@ -61,8 +63,8 @@ def start_refresh(self, cred, request): | |||
|
|||
def clear_error(self): |
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.
def clear_error(self): | |
def clear_error(self): -> 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.
done
google/auth/credentials.py
Outdated
from google.auth._refresh_worker import RefreshThreadManager | ||
from google.auth.credentials import Credentials |
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.
We're importing from the file itself? This doesn't seem right.
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.
from google.auth.credentials import Credentials |
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.
Ah, yeah, sorry you're right
Enables googleapis/python-cloud-core#302
I checked:
pyright google/auth/_credentials_base.py
pyright google/auth/_default.py
pyright google/auth/_refresh_worker.py
pyright google/auth/aio/credentials.py
pyright google/auth/credentials.py
pyright google/auth/metrics.py
pyright google/oauth2/service_account.py