You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/09/05 10:04:27 UTC

[GitHub] [airflow] ashb commented on a diff in pull request #26153: Removed deprecated contrib files and replace them with PEP-562 getattr

ashb commented on code in PR #26153:
URL: https://github.com/apache/airflow/pull/26153#discussion_r962730740


##########
airflow/utils/deprecation_tools.py:
##########
@@ -0,0 +1,46 @@
+# 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
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import functools
+import importlib
+import sys
+import warnings
+from types import ModuleType
+from typing import Dict
+
+
+def getattr_with_deprecation(imports: Dict[str, str], module: str, name: str):
+    target_class_full_name = imports.get(name)
+    if not target_class_full_name:
+        raise AttributeError(f"The module `{module!r}` has no attribute `{name!r}`")
+    warnings.warn(
+        f"The `{module}.{name}` class is deprecated. Please use `{target_class_full_name!r}`.",
+        DeprecationWarning,
+        stacklevel=2,
+    )
+    new_module, new_class_name = target_class_full_name.rsplit('.', 1)
+    return getattr(importlib.import_module(new_module), new_class_name)
+
+
+def add_deprecated_classes(module_imports: Dict[str, Dict[str, str]], module: str):
+    for submodule_name, imports in module_imports.items():
+        module_type = ModuleType(f"{module}.{submodule_name}")

Review Comment:
   Not sure that it matters, but this approach does "pollute" sys.modules with all deprecated modules when any contrib module is loaded.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org