Skip to content

Commit 7badc6a

Browse files
committed
Issue #642 Fix warning message of legacy aliases
1 parent f7f035f commit 7badc6a

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

openeo/internal/warnings.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ def test_warnings(stacklevel=1):
3535
)
3636

3737

38-
def legacy_alias(orig: Callable, name: str = "n/a", *, since: str, mode: str = "full"):
38+
def legacy_alias(orig: Callable, name: str, *, since: str, mode: str = "full"):
3939
"""
4040
Create legacy alias of given function/method/classmethod/staticmethod
4141
4242
:param orig: function/method to create legacy alias for
43-
:param name: name of the alias (unused)
43+
:param name: original name of the alias
4444
:param since: version since when this is alias is deprecated
4545
:param mode:
4646
- "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 = "
6969
def wrapper(*args, **kwargs):
7070
return orig(*args, **kwargs)
7171

72+
# Set deprecated name on the wrapper so that deprecation warnings use proper name.
73+
wrapper.__name__ = name
74+
7275
ref = f":py:{'meth' if 'method' in kind else 'func'}:`.{orig.__name__}`"
7376
message = f"Usage of this legacy {kind} is deprecated. Use {ref} instead."
7477

openeo/rest/job.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def describe(self) -> dict:
7676
"""
7777
return self.connection.get(f"/jobs/{self.job_id}", expected_status=200).json()
7878

79-
describe_job = legacy_alias(describe, since="0.20.0", mode="soft")
79+
describe_job = legacy_alias(describe, name="describe_job", since="0.20.0", mode="soft")
8080

8181
def status(self) -> str:
8282
"""
@@ -96,7 +96,7 @@ def delete(self):
9696
"""
9797
self.connection.delete(f"/jobs/{self.job_id}", expected_status=204)
9898

99-
delete_job = legacy_alias(delete, since="0.20.0", mode="soft")
99+
delete_job = legacy_alias(delete, name="delete_job", since="0.20.0", mode="soft")
100100

101101
@openeo_endpoint("GET /jobs/{job_id}/estimate")
102102
def estimate(self):
@@ -107,7 +107,7 @@ def estimate(self):
107107
currency = self.connection.capabilities().currency()
108108
return VisualDict('job-estimate', data=data, parameters={'currency': currency})
109109

110-
estimate_job = legacy_alias(estimate, since="0.20.0", mode="soft")
110+
estimate_job = legacy_alias(estimate, name="estimate_job", since="0.20.0", mode="soft")
111111

112112
@openeo_endpoint("POST /jobs/{job_id}/results")
113113
def start(self) -> BatchJob:
@@ -122,7 +122,7 @@ def start(self) -> BatchJob:
122122
self.connection.post(f"/jobs/{self.job_id}/results", expected_status=202)
123123
return self
124124

125-
start_job = legacy_alias(start, since="0.20.0", mode="soft")
125+
start_job = legacy_alias(start, name="start_job", since="0.20.0", mode="soft")
126126

127127
@openeo_endpoint("DELETE /jobs/{job_id}/results")
128128
def stop(self):
@@ -134,7 +134,7 @@ def stop(self):
134134
"""
135135
self.connection.delete(f"/jobs/{self.job_id}/results", expected_status=204)
136136

137-
stop_job = legacy_alias(stop, since="0.20.0", mode="soft")
137+
stop_job = legacy_alias(stop, name="stop_job", since="0.20.0", mode="soft")
138138

139139
def get_results_metadata_url(self, *, full: bool = False) -> str:
140140
"""Get results metadata URL"""

tests/internal/test_warnings.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def add(x, y):
4040
with pytest.warns(
4141
UserDeprecationWarning,
4242
match=re.escape(
43-
"Call to deprecated function (or staticmethod) add."
43+
"Call to deprecated function (or staticmethod) do_plus."
4444
" (Usage of this legacy function is deprecated. Use `.add` instead.)"
4545
" -- Deprecated since version v1.2."
4646
),
@@ -71,7 +71,7 @@ def add(self, x, y):
7171
with pytest.warns(
7272
UserDeprecationWarning,
7373
match=re.escape(
74-
"Call to deprecated method add."
74+
"Call to deprecated method do_plus."
7575
" (Usage of this legacy method is deprecated. Use `.add` instead.)"
7676
" -- Deprecated since version v1.2."
7777
),
@@ -103,7 +103,7 @@ def add(cls, x, y):
103103

104104
expected_warning = re.escape(
105105
# Workaround for bug in classmethod detection before Python 3.9 (see https://wrapt.readthedocs.io/en/latest/decorators.html#decorating-class-methods
106-
f"Call to deprecated {'class method' if sys.version_info >= (3, 9) else 'function (or staticmethod)'} add."
106+
f"Call to deprecated {'class method' if sys.version_info >= (3, 9) else 'function (or staticmethod)'} do_plus."
107107
" (Usage of this legacy class method is deprecated. Use `.add` instead.)"
108108
" -- Deprecated since version v1.2."
109109
)
@@ -138,7 +138,7 @@ def add(x, y):
138138
assert len(recwarn) == 0
139139

140140
expected_warning = re.escape(
141-
"Call to deprecated function (or staticmethod) add."
141+
"Call to deprecated function (or staticmethod) do_plus."
142142
" (Usage of this legacy static method is deprecated. Use `.add` instead.)"
143143
" -- Deprecated since version v1.2."
144144
)
@@ -157,7 +157,7 @@ def add(self, x, y):
157157
"""Add x and y."""
158158
return x + y
159159

160-
do_plus = legacy_alias(add, since="v1.2", mode="soft")
160+
do_plus = legacy_alias(add, name="do_plus", since="v1.2", mode="soft")
161161

162162
assert Foo.add.__doc__ == "Add x and y."
163163
assert Foo.do_plus.__doc__ == (

tests/rest/datacube/test_datacube100.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3394,10 +3394,10 @@ def test_create_job_invalid_header(self, con100, requests_mock, add_header, job_
33943394
_ = cube.create_job(out_format="GTiff")
33953395

33963396
def test_legacy_send_job(self, con100, requests_mock):
3397-
"""Legacy `DataCube.send_job` alis for `create_job"""
3397+
"""Legacy `DataCube.send_job` alias for `create_job"""
33983398
requests_mock.post(API_URL + "/jobs", json=self._get_handler_post_jobs())
33993399
cube = con100.load_collection("S2")
3400-
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."
3400+
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."
34013401
with pytest.warns(UserDeprecationWarning, match=re.escape(expected_warning)):
34023402
job = cube.send_job(out_format="GTiff")
34033403
assert job.job_id == "myj0b1"

0 commit comments

Comments
 (0)