Skip to content

Commit

Permalink
improve typing for openfaas provider (#9883)
Browse files Browse the repository at this point in the history
Co-authored-by: Kamil Breguła <mik-laj@users.noreply.github.com>
  • Loading branch information
morrme and mik-laj committed Jul 20, 2020
1 parent e7c87fe commit fc8d38d
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions airflow/providers/openfaas/hooks/openfaas.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
# specific language governing permissions and limitations
# under the License.

from typing import Any, Dict

import requests

from airflow.exceptions import AirflowException
Expand All @@ -29,7 +31,7 @@ class OpenFaasHook(BaseHook):
Interact with OpenFaaS to query, deploy, invoke and update function
:param function_name: Name of the function, Defaults to None
:type query: str
:type function_name: str
:param conn_id: openfaas connection to use, Defaults to open_faas_default
for example host : http://openfaas.faas.com, Conn Type : Http
:type conn_id: str
Expand All @@ -42,8 +44,8 @@ class OpenFaasHook(BaseHook):

def __init__(self,
function_name=None,
conn_id='open_faas_default',
*args, **kwargs):
conn_id: str = 'open_faas_default',
*args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.function_name = function_name
self.conn_id = conn_id
Expand All @@ -52,7 +54,7 @@ def get_conn(self):
conn = self.get_connection(self.conn_id)
return conn

def deploy_function(self, overwrite_function_if_exist, body):
def deploy_function(self, overwrite_function_if_exist: bool, body: Dict[str, Any]) -> None:
"""
Deploy OpenFaaS function
"""
Expand All @@ -70,7 +72,7 @@ def deploy_function(self, overwrite_function_if_exist, body):
else:
self.log.info("Function deployed %s", self.function_name)

def invoke_async_function(self, body):
def invoke_async_function(self, body: Dict[str, Any]) -> None:
"""
Invoking function
"""
Expand All @@ -83,7 +85,7 @@ def invoke_async_function(self, body):
self.log.error("Response status %d", response.status_code)
raise AirflowException('failed to invoke function')

def update_function(self, body):
def update_function(self, body: Dict[str, Any]) -> None:
"""
Update OpenFaaS function
"""
Expand All @@ -97,7 +99,7 @@ def update_function(self, body):
else:
self.log.info("Function was updated")

def does_function_exist(self):
def does_function_exist(self) -> bool:
"""
Whether OpenFaaS function exists or not
"""
Expand Down

0 comments on commit fc8d38d

Please sign in to comment.