Skip to content

Commit a893287

Browse files
Add DPNPBinaryFuncOutKw class to handle positional out deprecation
1 parent 00fbb7d commit a893287

File tree

3 files changed

+29
-40
lines changed

3 files changed

+29
-40
lines changed

doc/conf.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from dpnp.dpnp_algo.dpnp_elementwise_common import (
1414
DPNPBinaryFunc,
15+
DPNPBinaryFuncOutKw,
1516
DPNPUnaryFunc,
1617
DPNPUnaryTwoOutputsFunc,
1718
)
@@ -210,7 +211,13 @@
210211
# -- Options for todo extension ----------------------------------------------
211212
def _can_document_member(member, *args, **kwargs):
212213
if isinstance(
213-
member, (DPNPBinaryFunc, DPNPUnaryFunc, DPNPUnaryTwoOutputsFunc)
214+
member,
215+
(
216+
DPNPBinaryFunc,
217+
DPNPBinaryFuncOutKw,
218+
DPNPUnaryFunc,
219+
DPNPUnaryTwoOutputsFunc,
220+
),
214221
):
215222
return True
216223
return orig(member, *args, **kwargs)

dpnp/dpnp_algo/dpnp_elementwise_common.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
# THE POSSIBILITY OF SUCH DAMAGE.
2727
# *****************************************************************************
2828

29+
import warnings
30+
2931
import dpctl.tensor as dpt
3032
import dpctl.tensor._copy_utils as dtc
3133
import dpctl.tensor._tensor_impl as dti
@@ -48,6 +50,7 @@
4850
"DPNPI0",
4951
"DPNPAngle",
5052
"DPNPBinaryFunc",
53+
"DPNPBinaryFuncOutKw",
5154
"DPNPFix",
5255
"DPNPImag",
5356
"DPNPReal",
@@ -725,6 +728,21 @@ def outer(
725728
)
726729

727730

731+
class DPNPBinaryFuncOutKw(DPNPBinaryFunc):
732+
"""DPNPBinaryFunc that deprecates positional `out` argument."""
733+
734+
def __call__(self, *args, **kwargs):
735+
if len(args) > self.nin:
736+
warnings.warn(
737+
"Passing more than 2 positional arguments is deprecated. "
738+
"If you meant to use the third argument as an output, "
739+
"use the `out` keyword argument instead.",
740+
DeprecationWarning,
741+
stacklevel=2,
742+
)
743+
return super().__call__(*args, **kwargs)
744+
745+
728746
class DPNPAngle(DPNPUnaryFunc):
729747
"""Class that implements dpnp.angle unary element-wise functions."""
730748

dpnp/dpnp_iface_mathematical.py

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646

4747
import builtins
4848
import warnings
49-
from functools import wraps
5049

5150
import dpctl.tensor as dpt
5251
import dpctl.tensor._tensor_elementwise_impl as ti
@@ -67,6 +66,7 @@
6766
DPNPI0,
6867
DPNPAngle,
6968
DPNPBinaryFunc,
69+
DPNPBinaryFuncOutKw,
7070
DPNPFix,
7171
DPNPImag,
7272
DPNPReal,
@@ -3266,32 +3266,14 @@ def interp(x, xp, fp, left=None, right=None, period=None):
32663266
32673267
"""
32683268

3269-
_maximum_impl = DPNPBinaryFunc(
3269+
maximum = DPNPBinaryFuncOutKw(
32703270
"maximum",
32713271
ti._maximum_result_type,
32723272
ti._maximum,
32733273
_MAXIMUM_DOCSTRING,
32743274
)
32753275

32763276

3277-
@wraps(_maximum_impl)
3278-
def maximum(*args, **kwargs):
3279-
"""
3280-
Wrapper around `_maximum_impl` that emits a DeprecationWarning
3281-
when `out` is passed positionally.
3282-
3283-
"""
3284-
if len(args) >= 3 and "out" not in kwargs:
3285-
warnings.warn(
3286-
"Passing more than 2 positional arguments is deprecated. If you "
3287-
"meant to use the third argument as an output, use the `out` "
3288-
"keyword argument instead.",
3289-
DeprecationWarning,
3290-
stacklevel=2,
3291-
)
3292-
return _maximum_impl(*args, **kwargs)
3293-
3294-
32953277
_MINIMUM_DOCSTRING = """
32963278
Computes the minimum value for each element :math:`x1_i` of the input array `x1`
32973279
relative to the respective element :math:`x2_i` of the input array `x2`.
@@ -3382,32 +3364,14 @@ def maximum(*args, **kwargs):
33823364
array(-inf)
33833365
"""
33843366

3385-
_minimum_impl = DPNPBinaryFunc(
3367+
minimum = DPNPBinaryFuncOutKw(
33863368
"minimum",
33873369
ti._minimum_result_type,
33883370
ti._minimum,
33893371
_MINIMUM_DOCSTRING,
33903372
)
33913373

33923374

3393-
@wraps(_minimum_impl)
3394-
def minimum(*args, **kwargs):
3395-
"""
3396-
Wrapper around `_minimum_impl` that emits a DeprecationWarning
3397-
when `out` is passed positionally.
3398-
3399-
"""
3400-
if len(args) >= 3 and "out" not in kwargs:
3401-
warnings.warn(
3402-
"Passing more than 2 positional arguments is deprecated. If you "
3403-
"meant to use the third argument as an output, use the `out` "
3404-
"keyword argument instead.",
3405-
DeprecationWarning,
3406-
stacklevel=2,
3407-
)
3408-
return _minimum_impl(*args, **kwargs)
3409-
3410-
34113375
def modf(x1, **kwargs):
34123376
"""
34133377
Return the fractional and integral parts of an array, element-wise.

0 commit comments

Comments
 (0)