This is an automated email from the ASF dual-hosted git repository.

weilee 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 3c1124e054f feat(dataset): allow "airflow.dataset.metadata.Metadata" 
import for backward compat (#44413)
3c1124e054f is described below

commit 3c1124e054f9d795b0e9007041653888da9de6a8
Author: Wei Lee <[email protected]>
AuthorDate: Mon Dec 2 21:12:30 2024 +0800

    feat(dataset): allow "airflow.dataset.metadata.Metadata" import for 
backward compat (#44413)
---
 airflow/datasets/__init__.py                  |  7 +------
 airflow/datasets/{__init__.py => metadata.py} | 18 +++---------------
 tests/datasets/test_dataset.py                |  9 +++++++++
 3 files changed, 13 insertions(+), 21 deletions(-)

diff --git a/airflow/datasets/__init__.py b/airflow/datasets/__init__.py
index 3524466e58c..d7c51a30823 100644
--- a/airflow/datasets/__init__.py
+++ b/airflow/datasets/__init__.py
@@ -1,4 +1,3 @@
-#
 # Licensed to the Apache Software Foundation (ASF) under one
 # or more contributor license agreements.  See the NOTICE file
 # distributed with this work for additional information
@@ -38,8 +37,4 @@ warnings.warn(
     stacklevel=2,
 )
 
-
-__all__ = [
-    "Dataset",
-    "DatasetAlias",
-]
+__all__ = ["Dataset", "DatasetAlias"]
diff --git a/airflow/datasets/__init__.py b/airflow/datasets/metadata.py
similarity index 62%
copy from airflow/datasets/__init__.py
copy to airflow/datasets/metadata.py
index 3524466e58c..ef4e8037faa 100644
--- a/airflow/datasets/__init__.py
+++ b/airflow/datasets/metadata.py
@@ -1,4 +1,3 @@
-#
 # Licensed to the Apache Software Foundation (ASF) under one
 # or more contributor license agreements.  See the NOTICE file
 # distributed with this work for additional information
@@ -16,30 +15,19 @@
 # specific language governing permissions and limitations
 # under the License.
 
-# We do not use "from __future__ import annotations" here because it is not 
supported
-# by Pycharm when we want to make sure all imports in airflow work from 
namespace packages
-# Adding it automatically is excluded in pyproject.toml via I002 ruff rule 
exclusion
-
-# Make `airflow` a namespace package, supporting installing
-# airflow.providers.* in different locations (i.e. one in site, and one in user
-# lib.)  This is required by some IDEs to resolve the import paths.
 from __future__ import annotations
 
 import warnings
 
-from airflow.sdk.definitions.asset import AssetAlias as DatasetAlias, Dataset
+from airflow.sdk.definitions.asset.metadata import Metadata
 
 # TODO: Remove this module in Airflow 3.2
 
 warnings.warn(
     "Import from the airflow.dataset module is deprecated and "
-    "will be removed in the Airflow 3.2. Please import it from 
'airflow.sdk.definitions.asset'.",
+    "will be removed in the Airflow 3.2. Please import it from 
'airflow.sdk.definitions.asset.metadata'.",
     DeprecationWarning,
     stacklevel=2,
 )
 
-
-__all__ = [
-    "Dataset",
-    "DatasetAlias",
-]
+__all__ = ["Metadata"]
diff --git a/tests/datasets/test_dataset.py b/tests/datasets/test_dataset.py
index de1a9a5cc3a..4898bd5fd47 100644
--- a/tests/datasets/test_dataset.py
+++ b/tests/datasets/test_dataset.py
@@ -40,6 +40,15 @@ import pytest
                 "will be removed in the Airflow 3.2. Please import it from 
'airflow.sdk.definitions.asset'."
             ),
         ),
+        (
+            "airflow.datasets.metadata",
+            "Metadata",
+            (
+                "Import from the airflow.dataset module is deprecated and "
+                "will be removed in the Airflow 3.2. Please import it from "
+                "'airflow.sdk.definitions.asset.metadata'."
+            ),
+        ),
     ),
 )
 def test_backward_compat_import_before_airflow_3_2(module_path, attr_name, 
warning_message):

Reply via email to