Skip to content

Commit

Permalink
Always use Literal from typing_extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Taragolis committed Aug 27, 2023
1 parent 4f3d284 commit 7fec822
Show file tree
Hide file tree
Showing 17 changed files with 29 additions and 26 deletions.
4 changes: 2 additions & 2 deletions airflow/cli/commands/task_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
import sys
import textwrap
from contextlib import contextmanager, redirect_stderr, redirect_stdout, suppress
from typing import Generator, Union, cast
from typing import Generator, Protocol, Union, cast

import pendulum
from pendulum.parsing.exceptions import ParserError
from sqlalchemy import select
from sqlalchemy.orm.exc import NoResultFound
from sqlalchemy.orm.session import Session
from typing_extensions import Literal

from airflow import settings
from airflow.cli.simple_table import AirflowConsole
Expand All @@ -50,7 +51,6 @@
from airflow.settings import IS_K8S_EXECUTOR_POD
from airflow.ti_deps.dep_context import DepContext
from airflow.ti_deps.dependencies_deps import SCHEDULER_QUEUED_DEPS
from airflow.typing_compat import Literal, Protocol
from airflow.utils import cli as cli_utils
from airflow.utils.cli import (
get_dag,
Expand Down
2 changes: 1 addition & 1 deletion airflow/models/dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@
from pendulum.tz.timezone import Timezone
from sqlalchemy.orm.query import Query
from sqlalchemy.orm.session import Session
from typing_extensions import Literal

from airflow.datasets import Dataset
from airflow.decorators import TaskDecoratorCollection
from airflow.models.dagbag import DagBag
from airflow.models.operator import Operator
from airflow.models.slamiss import SlaMiss
from airflow.typing_compat import Literal
from airflow.utils.task_group import TaskGroup

log = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion airflow/models/dagrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@
from datetime import datetime

from sqlalchemy.orm import Query, Session
from typing_extensions import Literal

from airflow.models.dag import DAG
from airflow.models.operator import Operator
from airflow.typing_compat import Literal
from airflow.utils.types import ArgNotSet

CreatedTasks = TypeVar("CreatedTasks", Iterator["dict[str, Any]"], Iterator[TI])
Expand Down
2 changes: 1 addition & 1 deletion airflow/models/mappedoperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from typing import TYPE_CHECKING, Any, ClassVar, Collection, Iterable, Iterator, Mapping, Sequence, Union

import attr
from typing_extensions import Literal

from airflow import settings
from airflow.compat.functools import cache
Expand All @@ -51,7 +52,6 @@
from airflow.models.pool import Pool
from airflow.serialization.enums import DagAttributeTypes
from airflow.ti_deps.deps.mapped_task_expanded import MappedTaskIsExpanded
from airflow.typing_compat import Literal
from airflow.utils.context import context_update_for_unmapped
from airflow.utils.helpers import is_container, prevent_duplicates
from airflow.utils.types import NOTSET
Expand Down
3 changes: 2 additions & 1 deletion airflow/models/taskinstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
from sqlalchemy.orm.session import Session
from sqlalchemy.sql.elements import BooleanClauseList
from sqlalchemy.sql.expression import ColumnOperators
from typing_extensions import Literal

from airflow.models.abstractoperator import TaskStateChangeCallback
from airflow.models.baseoperator import BaseOperator
Expand All @@ -143,7 +144,7 @@
from airflow.models.dataset import DatasetEvent
from airflow.models.operator import Operator
from airflow.timetables.base import DataInterval
from airflow.typing_compat import Literal, TypeGuard
from airflow.typing_compat import TypeGuard
from airflow.utils.task_group import TaskGroup

# This is a workaround because mypy doesn't work with hybrid_property
Expand Down
3 changes: 2 additions & 1 deletion airflow/providers/amazon/aws/sensors/sqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
from __future__ import annotations

from functools import cached_property
from typing import TYPE_CHECKING, Any, Collection, Literal, Sequence
from typing import TYPE_CHECKING, Any, Collection, Sequence

from deprecated import deprecated
from typing_extensions import Literal

from airflow.configuration import conf
from airflow.exceptions import AirflowException
Expand Down
4 changes: 3 additions & 1 deletion airflow/providers/amazon/aws/transfers/sql_to_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import enum
from collections import namedtuple
from tempfile import NamedTemporaryFile
from typing import TYPE_CHECKING, Iterable, Literal, Mapping, Sequence
from typing import TYPE_CHECKING, Iterable, Mapping, Sequence

from typing_extensions import Literal

from airflow.exceptions import AirflowException
from airflow.hooks.base import BaseHook
Expand Down
4 changes: 3 additions & 1 deletion airflow/providers/amazon/aws/triggers/sqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
from __future__ import annotations

import asyncio
from typing import Any, AsyncIterator, Collection, Literal
from typing import Any, AsyncIterator, Collection

from typing_extensions import Literal

from airflow.exceptions import AirflowException
from airflow.providers.amazon.aws.hooks.base_aws import BaseAwsConnection
Expand Down
3 changes: 2 additions & 1 deletion airflow/providers/amazon/aws/utils/sqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@

import json
import logging
from typing import Any, Literal
from typing import Any

from jsonpath_ng import parse
from typing_extensions import Literal

log = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion airflow/providers/cncf/kubernetes/operators/pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@

if TYPE_CHECKING:
import jinja2
from typing_extensions import Literal

from airflow.providers.cncf.kubernetes.secret import Secret
from airflow.typing_compat import Literal
from airflow.utils.context import Context

alphanum_lower = string.ascii_lowercase + string.digits
Expand Down
4 changes: 2 additions & 2 deletions airflow/providers/cncf/kubernetes/utils/pod_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from contextlib import closing, suppress
from dataclasses import dataclass
from datetime import timedelta
from typing import TYPE_CHECKING, Generator, cast
from typing import TYPE_CHECKING, Generator, Protocol, cast

import pendulum
import tenacity
Expand All @@ -38,11 +38,11 @@
from pendulum import DateTime
from pendulum.parsing.exceptions import ParserError
from tenacity import before_log
from typing_extensions import Literal
from urllib3.exceptions import HTTPError as BaseHTTPError

from airflow.exceptions import AirflowException, AirflowProviderDeprecationWarning
from airflow.providers.cncf.kubernetes.pod_generator import PodDefaults
from airflow.typing_compat import Literal, Protocol
from airflow.utils.log.logging_mixin import LoggingMixin
from airflow.utils.timezone import utcnow

Expand Down
2 changes: 1 addition & 1 deletion airflow/providers/mongo/hooks/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
if TYPE_CHECKING:
from types import TracebackType

from airflow.typing_compat import Literal
from typing_extensions import Literal


class MongoHook(BaseHook):
Expand Down
3 changes: 2 additions & 1 deletion airflow/providers/salesforce/operators/bulk.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
from airflow.providers.salesforce.hooks.salesforce import SalesforceHook

if TYPE_CHECKING:
from airflow.typing_compat import Literal
from typing_extensions import Literal

from airflow.utils.context import Context


Expand Down
2 changes: 1 addition & 1 deletion airflow/providers_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
from typing import TYPE_CHECKING, Any, Callable, MutableMapping, NamedTuple, TypeVar, cast

from packaging.utils import canonicalize_name
from typing_extensions import Literal

from airflow.exceptions import AirflowOptionalProviderFeatureException
from airflow.hooks.filesystem import FSHook
from airflow.hooks.package_index import PackageIndexHook
from airflow.typing_compat import Literal
from airflow.utils import yaml
from airflow.utils.entry_points import entry_points_with_dist
from airflow.utils.log.logging_mixin import LoggingMixin
Expand Down
8 changes: 3 additions & 5 deletions airflow/typing_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@
import sys
from typing import Protocol, TypedDict, runtime_checkable

# Literal in 3.8 is limited to one single argument, not e.g. "Literal[1, 2]".
if sys.version_info >= (3, 9):
from typing import Literal
else:
from typing import Literal
# Literal from typing module has various issues in different Python versions, see:
# https://typing-extensions.readthedocs.io/en/latest/#Literal
from typing_extensions import Literal

if sys.version_info >= (3, 10):
from typing import ParamSpec, TypeGuard
Expand Down
2 changes: 1 addition & 1 deletion airflow/utils/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

from croniter import croniter
from dateutil.relativedelta import relativedelta # for doctest
from typing_extensions import Literal

from airflow.exceptions import RemovedInAirflow3Warning
from airflow.typing_compat import Literal
from airflow.utils import timezone

cron_presets: dict[str, str] = {
Expand Down
5 changes: 1 addition & 4 deletions dev/breeze/src/airflow_breeze/utils/selective_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
from re import match
from typing import Any, Dict, List, TypeVar

if sys.version_info >= (3, 9):
from typing import Literal
else:
from typing import Literal
from typing_extensions import Literal

from airflow_breeze.global_constants import (
ALL_PYTHON_MAJOR_MINOR_VERSIONS,
Expand Down

0 comments on commit 7fec822

Please sign in to comment.