-
Notifications
You must be signed in to change notification settings - Fork 98
Fix errors reported by mypy #490
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
Changes from 4 commits
3b1e53f
2f6ec47
2efe536
2e81249
278ecd7
fa4a9b1
0d187df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,12 +30,14 @@ | |
| BASE_URL = f'{PLANET_BASE_URL}/v0/auth' | ||
| ENV_API_KEY = 'PL_API_KEY' | ||
|
|
||
| AuthType = httpx.Auth | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolves |
||
|
|
||
|
|
||
| class Auth(metaclass=abc.ABCMeta): | ||
| '''Handle authentication information for use with Planet APIs.''' | ||
|
|
||
| @staticmethod | ||
| def from_key(key: str) -> Auth: | ||
| def from_key(key: str) -> AuthType: | ||
| '''Obtain authentication from api key. | ||
|
|
||
| Parameters: | ||
|
|
@@ -46,7 +48,7 @@ def from_key(key: str) -> Auth: | |
| return auth | ||
|
|
||
| @staticmethod | ||
| def from_file(filename: str = None) -> Auth: | ||
| def from_file(filename: str = None) -> AuthType: | ||
| '''Create authentication from secret file. | ||
|
|
||
| The secret file is named `.planet.json` and is stored in the user | ||
|
|
@@ -71,7 +73,7 @@ def from_file(filename: str = None) -> Auth: | |
| return auth | ||
|
|
||
| @staticmethod | ||
| def from_env(variable_name: str = None) -> Auth: | ||
| def from_env(variable_name: str = None) -> AuthType: | ||
| '''Create authentication from environment variable. | ||
|
|
||
| Reads the `PL_API_KEY` environment variable | ||
|
|
@@ -80,7 +82,7 @@ def from_env(variable_name: str = None) -> Auth: | |
| variable_name: Alternate environment variable. | ||
| ''' | ||
| variable_name = variable_name or ENV_API_KEY | ||
| api_key = os.getenv(variable_name) | ||
| api_key = os.getenv(variable_name, '') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolves The APIKeyAuth constructor does not take None as an argument ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a nice catch |
||
| try: | ||
| auth = APIKeyAuth(api_key) | ||
| LOGGER.debug(f'Auth set from environment variable {variable_name}') | ||
|
|
@@ -91,7 +93,7 @@ def from_env(variable_name: str = None) -> Auth: | |
| return auth | ||
|
|
||
| @staticmethod | ||
| def from_login(email: str, password: str, base_url: str = None) -> Auth: | ||
| def from_login(email: str, password: str, base_url: str = None) -> AuthType: | ||
| '''Create authentication from login email and password. | ||
|
|
||
| Note: To keep your password secure, the use of `getpass` is | ||
|
|
@@ -113,14 +115,18 @@ def from_login(email: str, password: str, base_url: str = None) -> Auth: | |
|
|
||
| @classmethod | ||
| @abc.abstractmethod | ||
| def from_dict(cls, data: dict) -> Auth: | ||
| def from_dict(cls, data: dict) -> AuthType: | ||
| pass | ||
|
|
||
| @property | ||
| @abc.abstractmethod | ||
| def value(self): | ||
| pass | ||
|
|
||
| @abc.abstractmethod | ||
| def to_dict(self) -> dict: | ||
| pass | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolves |
||
|
|
||
| def write(self, filename: str = None): | ||
| '''Write authentication information. | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,6 @@ | |
| from .orders import OrdersClient | ||
|
|
||
| __all__ = [ | ||
| DataClient, | ||
| OrdersClient, | ||
| 'DataClient', | ||
| 'OrdersClient', | ||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -175,11 +175,12 @@ async def create_search(self, | |
| url = self._searches_url() | ||
|
|
||
| # TODO: validate item_types | ||
| request_json = { | ||
| request_json: typing.Dict[str, typing.Any] = { | ||
|
||
| 'name': name, 'filter': search_filter, 'item_types': item_types | ||
| } | ||
| # QUESTION: can we just set the value to True or False above? | ||
|
||
| if enable_email: | ||
| request_json['__daily_email_enabled'] = True | ||
| request_json['__daily_email_enabled'] = enable_email | ||
sgillies marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| request = self._request(url, method='POST', json=request_json) | ||
| response = await self._do_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.
__all__requires strings, not objects.