From 482b40aed60a21de461d44cb848fa272e227f18d Mon Sep 17 00:00:00 2001 From: starone <53330796+Xiroo@users.noreply.github.com> Date: Thu, 14 Sep 2023 14:54:59 +0900 Subject: [PATCH 1/8] Remove float type python version in PythonVirtualEnvOperator Remove float type python version in PythonVirtualEnvOperator --- airflow/operators/python.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/airflow/operators/python.py b/airflow/operators/python.py index 4dd8727519849..802e83714b8d1 100644 --- a/airflow/operators/python.py +++ b/airflow/operators/python.py @@ -531,7 +531,7 @@ def __init__( *, python_callable: Callable, requirements: None | Iterable[str] | str = None, - python_version: str | int | float | None = None, + python_version: str | int | None = None, use_dill: bool = False, system_site_packages: bool = True, pip_install_options: list[str] | None = None, @@ -555,6 +555,11 @@ def __init__( "major versions for PythonVirtualenvOperator. Please use string_args." f"Sys version: {sys.version_info}. Venv version: {python_version}" ) + if type(python_version) is float: + raise AirflowException( + "Passing float as python_version is not supported for PythonVirtualenvOperator. " + "Since Python 3.10 is interpreted as 3.1. Please use string value instead." + ) if not is_venv_installed(): raise AirflowException("PythonVirtualenvOperator requires virtualenv, please install it.") if not requirements: From 2ce26fae85d52bb31627a283e1a34de9e8581e96 Mon Sep 17 00:00:00 2001 From: kyeonghoon Kim Date: Thu, 14 Sep 2023 17:02:33 +0900 Subject: [PATCH 2/8] Remove int type python version in PythonVirtualEnvOperator --- airflow/operators/python.py | 14 ++++++++------ tests/operators/test_python.py | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/airflow/operators/python.py b/airflow/operators/python.py index 802e83714b8d1..1fbd0dee28fb1 100644 --- a/airflow/operators/python.py +++ b/airflow/operators/python.py @@ -531,7 +531,7 @@ def __init__( *, python_callable: Callable, requirements: None | Iterable[str] | str = None, - python_version: str | int | None = None, + python_version: str | None = None, use_dill: bool = False, system_site_packages: bool = True, pip_install_options: list[str] | None = None, @@ -547,7 +547,7 @@ def __init__( ): if ( python_version - and str(python_version)[0] != str(sys.version_info.major) + and python_version[0] != str(sys.version_info.major) and (op_args or op_kwargs) ): raise AirflowException( @@ -555,10 +555,12 @@ def __init__( "major versions for PythonVirtualenvOperator. Please use string_args." f"Sys version: {sys.version_info}. Venv version: {python_version}" ) - if type(python_version) is float: - raise AirflowException( - "Passing float as python_version is not supported for PythonVirtualenvOperator. " - "Since Python 3.10 is interpreted as 3.1. Please use string value instead." + if type(python_version) is float or type(python_version) is int: + raise TypeError( + "Passing numeric type(int, float) as python_version " + "has been deprecated for PythonVirtualenvOperator. " + "Since Python 3.10 is interpreted as 3.1. " + "Please use string value instead." ) if not is_venv_installed(): raise AirflowException("PythonVirtualenvOperator requires virtualenv, please install it.") diff --git a/tests/operators/test_python.py b/tests/operators/test_python.py index d20949c618043..1d68d6543f560 100644 --- a/tests/operators/test_python.py +++ b/tests/operators/test_python.py @@ -965,7 +965,7 @@ def f(): return raise Exception - self.run_as_task(f, python_version=3, use_dill=False, requirements=["dill"]) + self.run_as_task(f, python_version="3", use_dill=False, requirements=["dill"]) def test_without_dill(self): def f(a): From 7a41e40868e2ef0ecc3888419f7ab3f636b9e1ce Mon Sep 17 00:00:00 2001 From: starone <53330796+Xiroo@users.noreply.github.com> Date: Thu, 14 Sep 2023 18:28:20 +0900 Subject: [PATCH 3/8] change deprecated to removed change deprecated to removed --- airflow/operators/python.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airflow/operators/python.py b/airflow/operators/python.py index 1fbd0dee28fb1..55e4278ab21b7 100644 --- a/airflow/operators/python.py +++ b/airflow/operators/python.py @@ -558,7 +558,7 @@ def __init__( if type(python_version) is float or type(python_version) is int: raise TypeError( "Passing numeric type(int, float) as python_version " - "has been deprecated for PythonVirtualenvOperator. " + "has been removed for PythonVirtualenvOperator. " "Since Python 3.10 is interpreted as 3.1. " "Please use string value instead." ) From 29979315ded3f019ba782ab0805c272961fbd194 Mon Sep 17 00:00:00 2001 From: starone <53330796+Xiroo@users.noreply.github.com> Date: Thu, 14 Sep 2023 20:04:24 +0900 Subject: [PATCH 4/8] change removal to deprecation change removal to deprecation --- airflow/operators/python.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/airflow/operators/python.py b/airflow/operators/python.py index 55e4278ab21b7..b5757b36b617d 100644 --- a/airflow/operators/python.py +++ b/airflow/operators/python.py @@ -547,7 +547,7 @@ def __init__( ): if ( python_version - and python_version[0] != str(sys.version_info.major) + and str(python_version[0]) != str(sys.version_info.major) and (op_args or op_kwargs) ): raise AirflowException( @@ -556,11 +556,10 @@ def __init__( f"Sys version: {sys.version_info}. Venv version: {python_version}" ) if type(python_version) is float or type(python_version) is int: - raise TypeError( - "Passing numeric type(int, float) as python_version " - "has been removed for PythonVirtualenvOperator. " - "Since Python 3.10 is interpreted as 3.1. " - "Please use string value instead." + warnings.warn( + "Passing numeric type(int, float) as python_version is deprecated. Please use string value instead.", + RemovedInAirflow3Warning, + stacklevel=2, ) if not is_venv_installed(): raise AirflowException("PythonVirtualenvOperator requires virtualenv, please install it.") From c4cc0d5c27e45449c2f63f3cf26ee66d34471300 Mon Sep 17 00:00:00 2001 From: starone <53330796+Xiroo@users.noreply.github.com> Date: Fri, 15 Sep 2023 09:54:05 +0900 Subject: [PATCH 5/8] fix typo fix typo --- airflow/operators/python.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airflow/operators/python.py b/airflow/operators/python.py index b5757b36b617d..c504ea36ebfdb 100644 --- a/airflow/operators/python.py +++ b/airflow/operators/python.py @@ -547,7 +547,7 @@ def __init__( ): if ( python_version - and str(python_version[0]) != str(sys.version_info.major) + and str(python_version)[0] != str(sys.version_info.major) and (op_args or op_kwargs) ): raise AirflowException( From 7c4181f675b86b1b749d0c91e28059a5cf5ea3dc Mon Sep 17 00:00:00 2001 From: starone <53330796+Xiroo@users.noreply.github.com> Date: Fri, 15 Sep 2023 10:36:57 +0900 Subject: [PATCH 6/8] fix line too long fix line too long --- airflow/operators/python.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/airflow/operators/python.py b/airflow/operators/python.py index c504ea36ebfdb..ded5b10139ce8 100644 --- a/airflow/operators/python.py +++ b/airflow/operators/python.py @@ -557,7 +557,8 @@ def __init__( ) if type(python_version) is float or type(python_version) is int: warnings.warn( - "Passing numeric type(int, float) as python_version is deprecated. Please use string value instead.", + "Passing numeric type(int, float) as python_version is deprecated. " + "Please use string value instead.", RemovedInAirflow3Warning, stacklevel=2, ) From 854293109722c8b941c6f41d8bec85ebedc0dd47 Mon Sep 17 00:00:00 2001 From: starone <53330796+Xiroo@users.noreply.github.com> Date: Fri, 15 Sep 2023 17:53:17 +0900 Subject: [PATCH 7/8] change condition statement change condition statement --- airflow/operators/python.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/airflow/operators/python.py b/airflow/operators/python.py index ded5b10139ce8..7ad3776fd837a 100644 --- a/airflow/operators/python.py +++ b/airflow/operators/python.py @@ -555,10 +555,10 @@ def __init__( "major versions for PythonVirtualenvOperator. Please use string_args." f"Sys version: {sys.version_info}. Venv version: {python_version}" ) - if type(python_version) is float or type(python_version) is int: + if not (isinstance(python_version, str) or python_version is None): warnings.warn( - "Passing numeric type(int, float) as python_version is deprecated. " - "Please use string value instead.", + "Passing non-string types (e.g. int or float) as python_version " + "is deprecated. Please use string value instead.", RemovedInAirflow3Warning, stacklevel=2, ) From 6b89b3a019d783455b45a9c2c3d9a0b814f0dfdf Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Fri, 15 Sep 2023 16:56:03 +0800 Subject: [PATCH 8/8] Use 'is not' --- airflow/operators/python.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airflow/operators/python.py b/airflow/operators/python.py index 7ad3776fd837a..b23d400f47cb9 100644 --- a/airflow/operators/python.py +++ b/airflow/operators/python.py @@ -555,7 +555,7 @@ def __init__( "major versions for PythonVirtualenvOperator. Please use string_args." f"Sys version: {sys.version_info}. Venv version: {python_version}" ) - if not (isinstance(python_version, str) or python_version is None): + if python_version is not None and not isinstance(python_version, str): warnings.warn( "Passing non-string types (e.g. int or float) as python_version " "is deprecated. Please use string value instead.",