Repository: Open-EO/openeo-python-client

Issue:
wrong deprecation warning on send_job
reported by @Katrijne-at-Vito
  

https://github.com/Open-EO/openeo-python-client/blob/f7f035f67d5afc57a4943a1f2389249e8cb0c250/tests/rest/datacube/test_datacube100.py#L3396-L3403

should say "Call to deprecated method send_job"

Discussion:

Patch:
diff --git a/openeo/internal/warnings.py b/openeo/internal/warnings.py
index 2c5335bc..fe9d5489 100644
--- a/openeo/internal/warnings.py
+++ b/openeo/internal/warnings.py
@@ -35,12 +35,12 @@ def test_warnings(stacklevel=1):
         )
 
 
-def legacy_alias(orig: Callable, name: str = "n/a", *, since: str, mode: str = "full"):
+def legacy_alias(orig: Callable, name: str, *, since: str, mode: str = "full"):
     """
     Create legacy alias of given function/method/classmethod/staticmethod
 
     :param orig: function/method to create legacy alias for
-    :param name: name of the alias (unused)
+    :param name: original name of the alias
     :param since: version since when this is alias is deprecated
     :param mode:
         - "full": raise warnings on calling, only have deprecation note as doc
@@ -69,6 +69,9 @@ def legacy_alias(orig: Callable, name: str = "n/a", *, since: str, mode: str = "
     def wrapper(*args, **kwargs):
         return orig(*args, **kwargs)
 
+    # Set deprecated name on the wrapper so that deprecation warnings use proper name.
+    wrapper.__name__ = name
+
     ref = f":py:{'meth' if 'method' in kind else 'func'}:`.{orig.__name__}`"
     message = f"Usage of this legacy {kind} is deprecated. Use {ref} instead."
 
diff --git a/openeo/rest/job.py b/openeo/rest/job.py
index 0dd3ff27..2248869b 100644
--- a/openeo/rest/job.py
+++ b/openeo/rest/job.py
@@ -76,7 +76,7 @@ class BatchJob:
         """
         return self.connection.get(f"/jobs/{self.job_id}", expected_status=200).json()
 
-    describe_job = legacy_alias(describe, since="0.20.0", mode="soft")
+    describe_job = legacy_alias(describe, name="describe_job", since="0.20.0", mode="soft")
 
     def status(self) -> str:
         """
@@ -96,7 +96,7 @@ class BatchJob:
         """
         self.connection.delete(f"/jobs/{self.job_id}", expected_status=204)
 
-    delete_job = legacy_alias(delete, since="0.20.0", mode="soft")
+    delete_job = legacy_alias(delete, name="delete_job", since="0.20.0", mode="soft")
 
     @openeo_endpoint("GET /jobs/{job_id}/estimate")
     def estimate(self):
@@ -107,7 +107,7 @@ class BatchJob:
         currency = self.connection.capabilities().currency()
         return VisualDict('job-estimate', data=data, parameters={'currency': currency})
 
-    estimate_job = legacy_alias(estimate, since="0.20.0", mode="soft")
+    estimate_job = legacy_alias(estimate, name="estimate_job", since="0.20.0", mode="soft")
 
     @openeo_endpoint("POST /jobs/{job_id}/results")
     def start(self) -> BatchJob:
@@ -122,7 +122,7 @@ class BatchJob:
         self.connection.post(f"/jobs/{self.job_id}/results", expected_status=202)
         return self
 
-    start_job = legacy_alias(start, since="0.20.0", mode="soft")
+    start_job = legacy_alias(start, name="start_job", since="0.20.0", mode="soft")
 
     @openeo_endpoint("DELETE /jobs/{job_id}/results")
     def stop(self):
@@ -134,7 +134,7 @@ class BatchJob:
         """
         self.connection.delete(f"/jobs/{self.job_id}/results", expected_status=204)
 
-    stop_job = legacy_alias(stop, since="0.20.0", mode="soft")
+    stop_job = legacy_alias(stop, name="stop_job", since="0.20.0", mode="soft")
 
     def get_results_metadata_url(self, *, full: bool = False) -> str:
         """Get results metadata URL"""


Test patch:
diff --git a/tests/internal/test_warnings.py b/tests/internal/test_warnings.py
index 4e7f6da8..30c1e013 100644
--- a/tests/internal/test_warnings.py
+++ b/tests/internal/test_warnings.py
@@ -40,7 +40,7 @@ def test_legacy_alias_function(recwarn):
     with pytest.warns(
         UserDeprecationWarning,
         match=re.escape(
-            "Call to deprecated function (or staticmethod) add."
+            "Call to deprecated function (or staticmethod) do_plus."
             " (Usage of this legacy function is deprecated. Use `.add` instead.)"
             " -- Deprecated since version v1.2."
         ),
@@ -71,7 +71,7 @@ def test_legacy_alias_method(recwarn):
     with pytest.warns(
         UserDeprecationWarning,
         match=re.escape(
-            "Call to deprecated method add."
+            "Call to deprecated method do_plus."
             " (Usage of this legacy method is deprecated. Use `.add` instead.)"
             " -- Deprecated since version v1.2."
         ),
@@ -103,7 +103,7 @@ def test_legacy_alias_classmethod(recwarn):
 
     expected_warning = re.escape(
         # Workaround for bug in classmethod detection before Python 3.9 (see https://wrapt.readthedocs.io/en/latest/decorators.html#decorating-class-methods
-        f"Call to deprecated {'class method' if sys.version_info >= (3, 9) else 'function (or staticmethod)'} add."
+        f"Call to deprecated {'class method' if sys.version_info >= (3, 9) else 'function (or staticmethod)'} do_plus."
         " (Usage of this legacy class method is deprecated. Use `.add` instead.)"
         " -- Deprecated since version v1.2."
     )
@@ -138,7 +138,7 @@ def test_legacy_alias_staticmethod(recwarn):
     assert len(recwarn) == 0
 
     expected_warning = re.escape(
-        "Call to deprecated function (or staticmethod) add."
+        "Call to deprecated function (or staticmethod) do_plus."
         " (Usage of this legacy static method is deprecated. Use `.add` instead.)"
         " -- Deprecated since version v1.2."
     )
@@ -157,7 +157,7 @@ def test_legacy_alias_method_soft(recwarn):
             """Add x and y."""
             return x + y
 
-        do_plus = legacy_alias(add, since="v1.2", mode="soft")
+        do_plus = legacy_alias(add, name="do_plus", since="v1.2", mode="soft")
 
     assert Foo.add.__doc__ == "Add x and y."
     assert Foo.do_plus.__doc__ == (
diff --git a/tests/rest/datacube/test_datacube100.py b/tests/rest/datacube/test_datacube100.py
index 2dba03eb..97e6bd46 100644
--- a/tests/rest/datacube/test_datacube100.py
+++ b/tests/rest/datacube/test_datacube100.py
@@ -3394,10 +3394,10 @@ class TestBatchJob:
             _ = cube.create_job(out_format="GTiff")
 
     def test_legacy_send_job(self, con100, requests_mock):
-        """Legacy `DataCube.send_job` alis for `create_job"""
+        """Legacy `DataCube.send_job` alias for `create_job"""
         requests_mock.post(API_URL + "/jobs", json=self._get_handler_post_jobs())
         cube = con100.load_collection("S2")
-        expected_warning = "Call to deprecated method create_job. (Usage of this legacy method is deprecated. Use `.create_job` instead.) -- Deprecated since version 0.10.0."
+        expected_warning = "Call to deprecated method send_job. (Usage of this legacy method is deprecated. Use `.create_job` instead.) -- Deprecated since version 0.10.0."
         with pytest.warns(UserDeprecationWarning, match=re.escape(expected_warning)):
             job = cube.send_job(out_format="GTiff")
         assert job.job_id == "myj0b1"