From 5fb125c365e1db5922137ad349140d185db67a46 Mon Sep 17 00:00:00 2001 From: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> Date: Wed, 29 Oct 2025 17:41:01 +0100 Subject: [PATCH 1/5] feat: preserver original signature of decorated methods --- src/ansys/geometry/core/misc/checks.py | 7 +++++++ tests/test_misc_checks.py | 29 ++++++++++++++++++++------ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/ansys/geometry/core/misc/checks.py b/src/ansys/geometry/core/misc/checks.py index 7b26d93aa4..a5a384102b 100644 --- a/src/ansys/geometry/core/misc/checks.py +++ b/src/ansys/geometry/core/misc/checks.py @@ -22,6 +22,7 @@ """Provides functions for performing common checks.""" from collections.abc import Iterable +import functools from typing import TYPE_CHECKING import warnings @@ -41,6 +42,7 @@ def ensure_design_is_active(method): is not necessary to call this. """ + @functools.wraps(method) def wrapper(self, *args, **kwargs): import ansys.geometry.core as pyansys_geometry from ansys.geometry.core.errors import GeometryRuntimeError @@ -310,6 +312,7 @@ def min_backend_version(major: int, minor: int, service_pack: int): from ansys.geometry.core.logger import LOG def backend_version_decorator(method): + @functools.wraps(method) def wrapper(self, *args, **kwargs): method_version = semver.Version(major, minor, service_pack) if hasattr(self, "_grpc_client"): @@ -365,6 +368,7 @@ def deprecated_method( """ def deprecated_decorator(method): + @functools.wraps(method) def wrapper(*args, **kwargs): msg = f"The method '{method.__name__}' is deprecated." if alternative: @@ -408,6 +412,7 @@ def deprecated_argument( """ def deprecated_decorator(method): + @functools.wraps(method) def wrapper(*args, **kwargs): if arg in kwargs and kwargs[arg] is not None: msg = f"The argument '{arg}' in '{method.__name__}' is deprecated." @@ -473,6 +478,7 @@ def graphics_required(method): Decorated method. """ + @functools.wraps(method) def wrapper(*args, **kwargs): run_if_graphics_required() return method(*args, **kwargs) @@ -524,6 +530,7 @@ def kwargs_passed_not_accepted(method): """ import inspect + @functools.wraps(method) def wrapper(*args, **kwargs): # Get the method signature sig = inspect.signature(method) diff --git a/tests/test_misc_checks.py b/tests/test_misc_checks.py index c2e6d5f436..4ae978137b 100644 --- a/tests/test_misc_checks.py +++ b/tests/test_misc_checks.py @@ -468,9 +468,26 @@ def my_method(arg1, arg2, **kwargs): ): my_method(arg1=1, arg2=2, arg3=3) - # TODO: This test fails, fix decorator #2338 - # @kwargs_passed_not_accepted - # @deprecated_argument("arg3") - # def my_method(arg1, arg2, **kwargs): - # """A method that accepts no keyword arguments.""" - # return arg1 + arg2 + @kwargs_passed_not_accepted + @deprecated_argument("arg3") + def my_method_diff_order(arg1, arg2, **kwargs): + """A method that accepts no keyword arguments.""" + return arg1 + arg2 + + # Call the method without kwargs - should not raise an error + assert my_method_diff_order(1, 2) == 3 + assert my_method_diff_order(arg1=1, arg2=2) == 3 + + # Call the method with kwargs - should raise an error + with pytest.raises( + TypeError, + match="The following keyword arguments are not accepted in the" + " method 'my_method_diff_order': unexpected_arg, another_one.", + ): + my_method_diff_order(1, 2, unexpected_arg=3, another_one="test") + + with pytest.raises( + TypeError, + match="The following keyword arguments are not accepted in the method 'my_method_diff_order': arg3.", + ): + my_method_diff_order(arg1=1, arg2=2, arg3=3) \ No newline at end of file From 0a0dbad0c1326d69c98da98ea367ae0490c18afb Mon Sep 17 00:00:00 2001 From: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> Date: Wed, 29 Oct 2025 17:41:19 +0100 Subject: [PATCH 2/5] fix: pre commit --- tests/test_misc_checks.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_misc_checks.py b/tests/test_misc_checks.py index 4ae978137b..113618f010 100644 --- a/tests/test_misc_checks.py +++ b/tests/test_misc_checks.py @@ -473,7 +473,7 @@ def my_method(arg1, arg2, **kwargs): def my_method_diff_order(arg1, arg2, **kwargs): """A method that accepts no keyword arguments.""" return arg1 + arg2 - + # Call the method without kwargs - should not raise an error assert my_method_diff_order(1, 2) == 3 assert my_method_diff_order(arg1=1, arg2=2) == 3 @@ -490,4 +490,4 @@ def my_method_diff_order(arg1, arg2, **kwargs): TypeError, match="The following keyword arguments are not accepted in the method 'my_method_diff_order': arg3.", ): - my_method_diff_order(arg1=1, arg2=2, arg3=3) \ No newline at end of file + my_method_diff_order(arg1=1, arg2=2, arg3=3) From ff20611409ea404ba0b902f54df125fb77889e7c Mon Sep 17 00:00:00 2001 From: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> Date: Wed, 29 Oct 2025 17:42:13 +0100 Subject: [PATCH 3/5] fix: pre commit --- tests/test_misc_checks.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/test_misc_checks.py b/tests/test_misc_checks.py index 113618f010..955ad691cf 100644 --- a/tests/test_misc_checks.py +++ b/tests/test_misc_checks.py @@ -481,13 +481,14 @@ def my_method_diff_order(arg1, arg2, **kwargs): # Call the method with kwargs - should raise an error with pytest.raises( TypeError, - match="The following keyword arguments are not accepted in the" - " method 'my_method_diff_order': unexpected_arg, another_one.", + match="The following keyword arguments are not accepted in the " + "method 'my_method_diff_order': unexpected_arg, another_one.", ): my_method_diff_order(1, 2, unexpected_arg=3, another_one="test") with pytest.raises( TypeError, - match="The following keyword arguments are not accepted in the method 'my_method_diff_order': arg3.", + match="The following keyword arguments are not accepted in the " + "method 'my_method_diff_order': arg3.", ): my_method_diff_order(arg1=1, arg2=2, arg3=3) From d3f504313acc5731fa0ccee06b68e6e24d4095c9 Mon Sep 17 00:00:00 2001 From: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Date: Wed, 29 Oct 2025 16:44:35 +0000 Subject: [PATCH 4/5] chore: adding changelog file 2346.added.md [dependabot-skip] --- doc/changelog.d/2346.added.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/changelog.d/2346.added.md diff --git a/doc/changelog.d/2346.added.md b/doc/changelog.d/2346.added.md new file mode 100644 index 0000000000..e25e02d082 --- /dev/null +++ b/doc/changelog.d/2346.added.md @@ -0,0 +1 @@ +Preserver original signature of decorated methods From 18c2be8bb9bc31394cb1644a0719eaef3b5db7a7 Mon Sep 17 00:00:00 2001 From: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Date: Wed, 29 Oct 2025 16:50:43 +0000 Subject: [PATCH 5/5] chore: adding changelog file 2346.added.md [dependabot-skip] --- doc/changelog.d/2346.added.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/changelog.d/2346.added.md b/doc/changelog.d/2346.added.md index e25e02d082..7d44fc9a7a 100644 --- a/doc/changelog.d/2346.added.md +++ b/doc/changelog.d/2346.added.md @@ -1 +1 @@ -Preserver original signature of decorated methods +Preserve original signature of decorated methods