Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ParamSpec to replace ... in Callable #25658

Merged
Merged
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
6 changes: 4 additions & 2 deletions airflow/utils/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from typing import Callable, Generator, TypeVar, cast

from airflow import settings
from airflow.typing_compat import ParamSpec


@contextlib.contextmanager
Expand All @@ -38,10 +39,11 @@ def create_session() -> Generator[settings.SASession, None, None]:
session.close()


PS = ParamSpec("PS")
RT = TypeVar("RT")


def find_session_idx(func: Callable[..., RT]) -> int:
def find_session_idx(func: Callable[PS, RT]) -> int:
"""Find session index in function call parameter."""
func_params = signature(func).parameters
try:
Expand All @@ -53,7 +55,7 @@ def find_session_idx(func: Callable[..., RT]) -> int:
return session_args_idx


def provide_session(func: Callable[..., RT]) -> Callable[..., RT]:
def provide_session(func: Callable[PS, RT]) -> Callable[PS, RT]:
"""
Function decorator that provides a session if it isn't provided.
If you want to reuse a session or run the function as part of a
Expand Down