Skip to content

Commit

Permalink
Improve importing the module in Airflow sensors package (#33801)
Browse files Browse the repository at this point in the history
  • Loading branch information
hussein-awala authored Aug 27, 2023
1 parent 4f3d284 commit 97091b1
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 14 deletions.
6 changes: 4 additions & 2 deletions airflow/sensors/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import time
import traceback
from datetime import timedelta
from typing import Any, Callable, Iterable
from typing import TYPE_CHECKING, Any, Callable, Iterable

from airflow import settings
from airflow.configuration import conf
Expand All @@ -43,13 +43,15 @@
from airflow.models.taskreschedule import TaskReschedule
from airflow.ti_deps.deps.ready_to_reschedule import ReadyToRescheduleDep
from airflow.utils import timezone
from airflow.utils.context import Context

# We need to keep the import here because GCSToLocalFilesystemOperator released in
# Google Provider before 3.0.0 imported apply_defaults from here.
# See https://github.com/apache/airflow/issues/16035
from airflow.utils.decorators import apply_defaults # noqa: F401

if TYPE_CHECKING:
from airflow.utils.context import Context

# As documented in https://dev.mysql.com/doc/refman/5.7/en/datetime.html.
_MYSQL_TIMESTAMP_MAX = datetime.datetime(2038, 1, 19, 3, 14, 7, tzinfo=timezone.utc)

Expand Down
6 changes: 4 additions & 2 deletions airflow/sensors/bash.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
import os
from subprocess import PIPE, STDOUT, Popen
from tempfile import NamedTemporaryFile, TemporaryDirectory, gettempdir
from typing import Sequence
from typing import TYPE_CHECKING, Sequence

from airflow.exceptions import AirflowFailException
from airflow.sensors.base import BaseSensorOperator
from airflow.utils.context import Context

if TYPE_CHECKING:
from airflow.utils.context import Context


class BashSensor(BaseSensorOperator):
Expand Down
6 changes: 4 additions & 2 deletions airflow/sensors/date_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
from __future__ import annotations

import datetime
from typing import Sequence
from typing import TYPE_CHECKING, Sequence

from airflow.sensors.base import BaseSensorOperator
from airflow.triggers.temporal import DateTimeTrigger
from airflow.utils import timezone
from airflow.utils.context import Context

if TYPE_CHECKING:
from airflow.utils.context import Context


class DateTimeSensor(BaseSensorOperator):
Expand Down
6 changes: 4 additions & 2 deletions airflow/sensors/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
import datetime
import os
from glob import glob
from typing import Sequence
from typing import TYPE_CHECKING, Sequence

from airflow.hooks.filesystem import FSHook
from airflow.sensors.base import BaseSensorOperator
from airflow.utils.context import Context

if TYPE_CHECKING:
from airflow.utils.context import Context


class FileSensor(BaseSensorOperator):
Expand Down
7 changes: 5 additions & 2 deletions airflow/sensors/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
# under the License.
from __future__ import annotations

from typing import Any, Callable, Mapping, Sequence
from typing import TYPE_CHECKING, Any, Callable, Mapping, Sequence

from airflow.sensors.base import BaseSensorOperator, PokeReturnValue
from airflow.utils.context import Context, context_merge
from airflow.utils.context import context_merge
from airflow.utils.operator_helpers import determine_kwargs

if TYPE_CHECKING:
from airflow.utils.context import Context


class PythonSensor(BaseSensorOperator):
"""
Expand Down
6 changes: 5 additions & 1 deletion airflow/sensors/time_delta.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@
# under the License.
from __future__ import annotations

from typing import TYPE_CHECKING

from airflow.exceptions import AirflowSkipException
from airflow.sensors.base import BaseSensorOperator
from airflow.triggers.temporal import DateTimeTrigger
from airflow.utils import timezone
from airflow.utils.context import Context

if TYPE_CHECKING:
from airflow.utils.context import Context


class TimeDeltaSensor(BaseSensorOperator):
Expand Down
5 changes: 4 additions & 1 deletion airflow/sensors/time_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@
from __future__ import annotations

import datetime
from typing import TYPE_CHECKING

from airflow.sensors.base import BaseSensorOperator
from airflow.triggers.temporal import DateTimeTrigger
from airflow.utils import timezone
from airflow.utils.context import Context

if TYPE_CHECKING:
from airflow.utils.context import Context


class TimeSensor(BaseSensorOperator):
Expand Down
6 changes: 4 additions & 2 deletions airflow/sensors/weekday.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@
from __future__ import annotations

import warnings
from typing import Iterable
from typing import TYPE_CHECKING, Iterable

from airflow.exceptions import RemovedInAirflow3Warning
from airflow.sensors.base import BaseSensorOperator
from airflow.utils import timezone
from airflow.utils.context import Context
from airflow.utils.weekday import WeekDay

if TYPE_CHECKING:
from airflow.utils.context import Context


class DayOfWeekSensor(BaseSensorOperator):
"""
Expand Down

0 comments on commit 97091b1

Please sign in to comment.