This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new ad4717b24b Use ParamSpec to replace ... in Callable (#25658)
ad4717b24b is described below
commit ad4717b24b5a85447f2bb9769c4e8d4ded89ad70
Author: Tzu-ping Chung <[email protected]>
AuthorDate: Fri Aug 12 22:09:56 2022 +0800
Use ParamSpec to replace ... in Callable (#25658)
For whatever reason, this makes PyLance able to infer the wrapped
function's signature, which is a nice improvement.
---
airflow/utils/session.py | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/airflow/utils/session.py b/airflow/utils/session.py
index 377ff55cbf..b349671042 100644
--- a/airflow/utils/session.py
+++ b/airflow/utils/session.py
@@ -20,6 +20,7 @@ from inspect import signature
from typing import Callable, Generator, TypeVar, cast
from airflow import settings
+from airflow.typing_compat import ParamSpec
@contextlib.contextmanager
@@ -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:
@@ -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