Skip to content

Commit b99506d

Browse files
authored
Fix issue where double decorator does not parse function name (#320)
* fix issue where double decorator does not parse function name * add unittest * fixup imports * remove double preprocessing
1 parent 08c1e16 commit b99506d

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

ultraplot/axes/plot.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5266,7 +5266,6 @@ def streamplot(self, x, y, u, v, c, **kwargs):
52665266
return m
52675267

52685268
@inputs._parse_triangulation_with_preprocess("x", "y", "z", keywords=["triangles"])
5269-
@inputs._preprocess_or_redirect("x", "y", "z")
52705269
@docstring._concatenate_inherited
52715270
@docstring._snippet_manager
52725271
def tricontour(self, *args, **kwargs):
@@ -5308,7 +5307,6 @@ def tricontour(self, *args, **kwargs):
53085307
return m
53095308

53105309
@inputs._parse_triangulation_with_preprocess("x", "y", "z", keywords=["triangles"])
5311-
@inputs._preprocess_or_redirect("x", "y", "z")
53125310
@docstring._concatenate_inherited
53135311
@docstring._snippet_manager
53145312
def tricontourf(self, *args, **kwargs):

ultraplot/internals/inputs.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,16 +282,22 @@ def _parse_triangulation_with_preprocess(*keys, keywords=None, allow_extra=True)
282282
"""
283283

284284
def _decorator(func):
285-
@_preprocess_or_redirect(*keys, keywords=keywords, allow_extra=allow_extra)
286-
def wrapper(self, *args, **kwargs):
287-
# Parse triangulation inputs after preprocessing
285+
def triangulation_wrapper(self, *args, **kwargs):
288286
triangulation, z, remaining_args, updated_kwargs = (
289287
_parse_triangulation_inputs(*args, **kwargs)
290288
)
291-
# Call the original function with parsed inputs
292289
return func(self, triangulation, z, *remaining_args, **updated_kwargs)
293290

294-
return wrapper
291+
# Manually set the name to the original function's name
292+
triangulation_wrapper.__name__ = func.__name__
293+
294+
final_wrapper = _preprocess_or_redirect(
295+
*keys, keywords=keywords, allow_extra=allow_extra
296+
)(triangulation_wrapper)
297+
298+
# Finally make sure all other metadata is correct
299+
functools.update_wrapper(final_wrapper, func)
300+
return final_wrapper
295301

296302
return _decorator
297303

ultraplot/tests/test_inputs.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import ultraplot as uplt, pytest, numpy as np
2+
from unittest.mock import Mock
23

34

45
@pytest.mark.parametrize(
@@ -16,3 +17,19 @@ def test_to_numpy_array(data, dtype):
1617
"""
1718
arr = uplt.internals.inputs._to_numpy_array(data)
1819
assert arr.dtype == dtype, f"Expected dtype {dtype}, got {arr.dtype}"
20+
21+
22+
def test_name_preserved_and_args_processed():
23+
"""
24+
Check if the name is preserved across nested decoration
25+
for tri-related functions
26+
"""
27+
parser_mock = Mock(return_value=("triang", "zval", None, None))
28+
29+
def tripcolor(self, tri, z, extra=None, kw=None):
30+
return "ok"
31+
32+
decorated = uplt.internals.inputs._parse_triangulation_with_preprocess()(tripcolor)
33+
34+
# Test that the decorator preserves the function name
35+
assert decorated.__name__ == "tripcolor"

0 commit comments

Comments
 (0)