Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion airflow/hooks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# fmt: off
# fmt:, off

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a typo?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# fmt:, off
# fmt: off

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Does it even do anything?)

@potiuk potiuk Sep 12, 2022

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah They were small corrections I've fixed to make the PR's green (my initial replace screwed up and joined those with from __future__ import annotations.

Yeah. They actualy do (and I think the comma does not really matter) - they prevent Black from re-formatting those files . The problem with such long names of classes we have in the dict that (despite the max-line-length) it will make lines too long and they fail in flake. One of the very few cases where black is WRONG.

@potiuk potiuk Sep 12, 2022

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will remove those comas.

"""Hooks."""
from __future__ import annotations

from airflow.utils.deprecation_tools import add_deprecated_classes

__deprecated_classes = {
Expand Down
18 changes: 10 additions & 8 deletions airflow/hooks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
# specific language governing permissions and limitations
# under the License.
"""Base class for all hooks"""
from __future__ import annotations

import logging
import warnings
from typing import TYPE_CHECKING, Any, Dict, List
from typing import TYPE_CHECKING, Any

from airflow.exceptions import RemovedInAirflow3Warning
from airflow.typing_compat import Protocol
Expand All @@ -40,7 +42,7 @@ class BaseHook(LoggingMixin):
"""

@classmethod
def get_connections(cls, conn_id: str) -> List["Connection"]:
def get_connections(cls, conn_id: str) -> list[Connection]:
"""
Get all connections as an iterable, given the connection id.

Expand All @@ -56,7 +58,7 @@ def get_connections(cls, conn_id: str) -> List["Connection"]:
return [cls.get_connection(conn_id)]

@classmethod
def get_connection(cls, conn_id: str) -> "Connection":
def get_connection(cls, conn_id: str) -> Connection:
"""
Get connection, given connection id.

Expand All @@ -70,7 +72,7 @@ def get_connection(cls, conn_id: str) -> "Connection":
return conn

@classmethod
def get_hook(cls, conn_id: str) -> "BaseHook":
def get_hook(cls, conn_id: str) -> BaseHook:
"""
Returns default hook for this connection id.

Expand All @@ -87,11 +89,11 @@ def get_conn(self) -> Any:
raise NotImplementedError()

@classmethod
def get_connection_form_widgets(cls) -> Dict[str, Any]:
def get_connection_form_widgets(cls) -> dict[str, Any]:
...

@classmethod
def get_ui_field_behaviour(cls) -> Dict[str, Any]:
def get_ui_field_behaviour(cls) -> dict[str, Any]:
...


Expand Down Expand Up @@ -140,7 +142,7 @@ def get_ui_field_behaviour(cls):
hook_name: str

@staticmethod
def get_connection_form_widgets() -> Dict[str, Any]:
def get_connection_form_widgets() -> dict[str, Any]:
"""
Returns dictionary of widgets to be added for the hook to handle extra values.

Expand All @@ -156,7 +158,7 @@ def get_connection_form_widgets() -> Dict[str, Any]:
...

@staticmethod
def get_ui_field_behaviour() -> Dict[str, Any]:
def get_ui_field_behaviour() -> dict[str, Any]:
"""
Returns dictionary describing customizations to implement in javascript handling the
connection form. Should be compliant with airflow/customized_form_field_behaviours.schema.json'
Expand Down
2 changes: 2 additions & 0 deletions airflow/hooks/dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from __future__ import annotations

import warnings

from airflow.exceptions import RemovedInAirflow3Warning
Expand Down
2 changes: 1 addition & 1 deletion airflow/hooks/filesystem.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.
#
from __future__ import annotations

from airflow.hooks.base import BaseHook

Expand Down
11 changes: 6 additions & 5 deletions airflow/hooks/subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from __future__ import annotations

import contextlib
import os
import signal
from collections import namedtuple
from subprocess import PIPE, STDOUT, Popen
from tempfile import TemporaryDirectory, gettempdir
from typing import Dict, List, Optional

from airflow.hooks.base import BaseHook

Expand All @@ -31,15 +32,15 @@ class SubprocessHook(BaseHook):
"""Hook for running processes with the ``subprocess`` module"""

def __init__(self) -> None:
self.sub_process: Optional[Popen[bytes]] = None
self.sub_process: Popen[bytes] | None = None
super().__init__()

def run_command(
self,
command: List[str],
env: Optional[Dict[str, str]] = None,
command: list[str],
env: dict[str, str] | None = None,
output_encoding: str = 'utf-8',
cwd: Optional[str] = None,
cwd: str | None = None,
) -> SubprocessResult:
"""
Execute the command.
Expand Down