Skip to content

Commit

Permalink
Completed D400 & D401 for airflow/api/* directory (#27716)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdsoha committed Nov 16, 2022
1 parent e56adc8 commit 9b025e4
Show file tree
Hide file tree
Showing 18 changed files with 60 additions and 44 deletions.
4 changes: 2 additions & 2 deletions airflow/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
"""Authentication backend"""
"""Authentication backend."""
from __future__ import annotations

import logging
Expand All @@ -28,7 +28,7 @@


def load_auth():
"""Loads authentication backends"""
"""Load authentication backends."""
auth_backends = "airflow.api.auth.backend.default"
try:
auth_backends = conf.get("api", "auth_backends")
Expand Down
8 changes: 4 additions & 4 deletions airflow/api/auth/backend/basic_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
"""Basic authentication backend"""
"""Basic authentication backend."""
from __future__ import annotations

from functools import wraps
Expand All @@ -31,14 +31,14 @@


def init_app(_):
"""Initializes authentication backend"""
"""Initialize authentication backend."""


T = TypeVar("T", bound=Callable)


def auth_current_user() -> User | None:
"""Authenticate and set current user if Authorization header exists"""
"""Authenticate and set current user if Authorization header exists."""
auth = request.authorization
if auth is None or not auth.username or not auth.password:
return None
Expand All @@ -55,7 +55,7 @@ def auth_current_user() -> User | None:


def requires_authentication(function: T):
"""Decorator for functions that require authentication"""
"""Decorate functions that require authentication."""

@wraps(function)
def decorated(*args, **kwargs):
Expand Down
6 changes: 3 additions & 3 deletions airflow/api/auth/backend/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
"""Default authentication backend - everything is allowed"""
"""Default authentication backend - everything is allowed."""
from __future__ import annotations

from functools import wraps
Expand All @@ -25,14 +25,14 @@


def init_app(_):
"""Initializes authentication backend"""
"""Initialize authentication backend."""


T = TypeVar("T", bound=Callable)


def requires_authentication(function: T):
"""Decorator for functions that require authentication"""
"""Decorate functions that require authentication."""

@wraps(function)
def decorated(*args, **kwargs):
Expand Down
6 changes: 3 additions & 3 deletions airflow/api/auth/backend/deny_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
"""Authentication backend that denies all requests"""
"""Authentication backend that denies all requests."""
from __future__ import annotations

from functools import wraps
Expand All @@ -27,14 +27,14 @@


def init_app(_):
"""Initializes authentication"""
"""Initialize authentication."""


T = TypeVar("T", bound=Callable)


def requires_authentication(function: T):
"""Decorator for functions that require authentication"""
"""Decorate functions that require authentication."""

@wraps(function)
def decorated(*args, **kwargs):
Expand Down
8 changes: 4 additions & 4 deletions airflow/api/auth/backend/kerberos_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@


class KerberosService:
"""Class to keep information about the Kerberos Service initialized"""
"""Class to keep information about the Kerberos Service initialized."""

def __init__(self):
self.service_name = None
Expand All @@ -71,7 +71,7 @@ def __init__(self):


def init_app(app):
"""Initializes application with kerberos"""
"""Initialize application with kerberos."""
hostname = app.config.get("SERVER_NAME")
if not hostname:
hostname = getfqdn()
Expand All @@ -95,7 +95,7 @@ def init_app(app):

def _unauthorized():
"""
Indicate that authorization is required
Indicate that authorization is required.
:return:
"""
return Response("Unauthorized", 401, {"WWW-Authenticate": "Negotiate"})
Expand Down Expand Up @@ -131,7 +131,7 @@ def _gssapi_authenticate(token):


def requires_authentication(function: T):
"""Decorator for functions that require authentication with Kerberos"""
"""Decorate functions that require authentication with Kerberos."""

@wraps(function)
def decorated(*args, **kwargs):
Expand Down
6 changes: 3 additions & 3 deletions airflow/api/auth/backend/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
"""Session authentication backend"""
"""Session authentication backend."""
from __future__ import annotations

from functools import wraps
Expand All @@ -26,14 +26,14 @@


def init_app(_):
"""Initializes authentication backend"""
"""Initialize authentication backend."""


T = TypeVar("T", bound=Callable)


def requires_authentication(function: T):
"""Decorator for functions that require authentication"""
"""Decorate functions that require authentication."""

@wraps(function)
def decorated(*args, **kwargs):
Expand Down
4 changes: 2 additions & 2 deletions airflow/api/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
"""API Client that allows interacting with Airflow API"""
"""API Client that allows interacting with Airflow API."""
from __future__ import annotations

from importlib import import_module
Expand All @@ -26,7 +26,7 @@


def get_current_api_client() -> Client:
"""Return current API Client based on current Airflow configuration"""
"""Return current API Client based on current Airflow configuration."""
api_module = import_module(conf.get_mandatory_value("cli", "api_client"))
auth_backends = api.load_auth()
session = None
Expand Down
2 changes: 1 addition & 1 deletion airflow/api/client/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def delete_pool(self, name):

def get_lineage(self, dag_id: str, execution_date: str):
"""
Return the lineage information for the dag on this execution date
Return the lineage information for the dag on this execution date.
:param dag_id:
:param execution_date:
:return:
Expand Down
2 changes: 1 addition & 1 deletion airflow/api/client/json_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
"""JSON API Client"""
"""JSON API Client."""
from __future__ import annotations

from urllib.parse import urljoin
Expand Down
2 changes: 1 addition & 1 deletion airflow/api/client/local_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
"""Local client API"""
"""Local client API."""
from __future__ import annotations

from airflow.api.client import api_client
Expand Down
2 changes: 2 additions & 0 deletions airflow/api/common/delete_dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
@provide_session
def delete_dag(dag_id: str, keep_records_in_log: bool = True, session=None) -> int:
"""
Delete a DAG by a dag_id.
:param dag_id: the dag_id of the DAG to delete
:param keep_records_in_log: whether keep records of the given dag_id
in the Log table in the backend database (for reasons like auditing).
Expand Down
4 changes: 2 additions & 2 deletions airflow/api/common/experimental/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


def check_and_get_dag(dag_id: str, task_id: str | None = None) -> DagModel:
"""Checks that DAG exists and in case it is specified that Task exist"""
"""Check DAG existence and in case it is specified that Task exists."""
dag_model = DagModel.get_current(dag_id)
if dag_model is None:
raise DagNotFound(f"Dag id {dag_id} not found in DagModel")
Expand All @@ -42,7 +42,7 @@ def check_and_get_dag(dag_id: str, task_id: str | None = None) -> DagModel:


def check_and_get_dagrun(dag: DagModel, execution_date: datetime) -> DagRun:
"""Get DagRun object and check that it exists"""
"""Get DagRun object and check that it exists."""
dagrun = dag.get_dagrun(execution_date=execution_date)
if not dagrun:
error_message = f"Dag Run for date {execution_date} not found in dag {dag.dag_id}"
Expand Down
2 changes: 1 addition & 1 deletion airflow/api/common/experimental/get_dag_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

def get_dag_runs(dag_id: str, state: str | None = None) -> list[dict[str, Any]]:
"""
Returns a list of Dag Runs for a specific DAG ID.
Return a list of Dag Runs for a specific DAG ID.
:param dag_id: String identifier of a DAG
:param state: queued|running|success...
Expand Down
4 changes: 2 additions & 2 deletions airflow/api/common/experimental/get_lineage.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
"""Lineage apis"""
"""Lineage APIs."""
from __future__ import annotations

import collections
Expand All @@ -34,7 +34,7 @@
def get_lineage(
dag_id: str, execution_date: datetime.datetime, *, session: Session = NEW_SESSION
) -> dict[str, dict[str, Any]]:
"""Gets the lineage information for dag specified."""
"""Get lineage information for dag specified."""
dag = check_and_get_dag(dag_id)
dagrun = check_and_get_dagrun(dag, execution_date)

Expand Down
2 changes: 1 addition & 1 deletion airflow/api/common/experimental/get_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
"""Task APIs.."""
"""Task APIs."""
from __future__ import annotations

from deprecated import deprecated
Expand Down
1 change: 1 addition & 0 deletions airflow/api/common/experimental/get_task_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
"""Task instance APIs."""
from __future__ import annotations

from datetime import datetime
Expand Down
Loading

0 comments on commit 9b025e4

Please sign in to comment.