o-nikolas commented on code in PR #77574:
URL: https://github.com/apache/airflow/pull/77574#discussion_r4690373679


##########
providers/amazon/src/airflow/providers/amazon/aws/utils/deprecation.py:
##########
@@ -0,0 +1,133 @@
+# 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.
+from __future__ import annotations
+
+import sys
+import warnings
+from typing import TYPE_CHECKING
+
+from airflow.exceptions import AirflowProviderDeprecationWarning
+from airflow.providers.amazon.aws.exceptions import RemovedFeatureError
+
+if TYPE_CHECKING:
+    from types import FrameType
+
+UPGRADE_GUIDE_URL = 
"https://airflow.apache.org/docs/apache-airflow-providers-amazon/stable/upgrading.html";
+
+NEXT_MAJOR_VERSION = "10.0.0"
+
+# Off in every release before ``NEXT_MAJOR_VERSION``; the pull request that 
releases that version turns it
+# on. It is not derived from the provider version, which can be bumped to a 
major for an unrelated
+# breaking change. Tests patch it to cover both settings.
+_NEXT_MAJOR_ENABLED = False
+
+
+def is_next_major_enabled() -> bool:
+    """
+    Tell whether provider code behaves the way it does in 
``NEXT_MAJOR_VERSION``.
+
+    Code whose behaviour changes in that version carries both behaviours and 
asks this each time it
+    runs. Reading it at import time would fix the answer before a test can 
change it.
+    """
+    return _NEXT_MAJOR_ENABLED
+
+
+def _get_module_name(frame: FrameType) -> str:
+    return frame.f_globals.get("__name__", "")
+
+
+def _is_provider_code(frame: FrameType) -> bool:
+    return _get_module_name(frame).startswith("airflow.providers.")
+
+
+def _is_airflow_code(frame: FrameType) -> bool:
+    name = _get_module_name(frame)
+    return name == "airflow" or name.startswith("airflow.")
+
+
+def _is_user_code(frame: FrameType) -> bool:
+    if _is_airflow_code(frame) or _get_module_name(frame).partition(".")[0] in 
sys.stdlib_module_names:
+        return False
+    filename = frame.f_code.co_filename
+    return "site-packages" not in filename and "dist-packages" not in filename
+
+
+def _find_user_caller(provider_frame: FrameType) -> FrameType | None:
+    """
+    Return the frame of the user code that called the provider directly, if 
there is one.
+
+    There is none when Airflow calls the provider code, as it does for 
``execute``, ``poke`` and a
+    trigger's ``run``, or when the call comes through the standard library or 
an installed library. The
+    frame that would be found by walking further up in those cases is whatever 
started the task or the
+    wrapper that made the call, not the code that has to change.
+    """
+    caller: FrameType | None = provider_frame
+    while caller and _is_provider_code(caller):
+        called, caller = caller, caller.f_back
+        # ``BaseOperatorMeta`` wraps every operator ``__init__``, which puts 
one frame of Airflow's own
+        # between a provider ``__init__`` and the code that instantiates the 
operator.
+        if (
+            caller
+            and called.f_code.co_name == "__init__"
+            and _is_airflow_code(caller)
+            and not _is_provider_code(caller)
+        ):
+            caller = caller.f_back
+    return caller if caller and _is_user_code(caller) else None
+
+
+def warn_deprecated(message: str, *, removal_version: str) -> None:

Review Comment:
   Small cross-PR thing: the example in the deprecation policy page in #77457 
still shows `warnings.warn(..., stacklevel=2)`, which is the pattern this PR 
says gets dropped for user code. Could whichever of the two merges second 
switch that example to `warn_deprecated`?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to