Skip to content

Commit 377c89f

Browse files
committed
Some docs and syntax niceties
1 parent 15114b7 commit 377c89f

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

Diff for: array_api_tests/test_signatures.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""
2+
Tests for function/method signatures compliance
3+
24
We're not interested in being 100% strict - instead we focus on areas which
35
could affect interop, e.g. with
46
@@ -20,7 +22,7 @@ def squeeze(x, /, axis):
2022
"""
2123
from inspect import Parameter, Signature, signature
2224
from types import FunctionType
23-
from typing import Any, Callable, Dict, List, Literal, Sequence, get_args
25+
from typing import Any, Callable, Dict, List, Literal, get_args
2426

2527
import pytest
2628
from hypothesis import given, note, settings
@@ -67,10 +69,7 @@ def _test_inspectable_func(sig: Signature, stub_sig: Signature):
6769
param = params[i]
6870

6971
# We're not interested in the name if it isn't actually used
70-
if stub_param.kind not in [
71-
Parameter.POSITIONAL_ONLY,
72-
*VAR_KINDS,
73-
]:
72+
if stub_param.kind not in [Parameter.POSITIONAL_ONLY, *VAR_KINDS]:
7473
assert (
7574
param.name == stub_param.name
7675
), f"Expected argument '{param.name}' to be named '{stub_param.name}'"
@@ -100,7 +99,7 @@ def get_dtypes_strategy(func_name: str) -> st.SearchStrategy[DataType]:
10099
return xps.scalar_dtypes()
101100

102101

103-
def make_pretty_func(func_name: str, args: Sequence[Any], kwargs: Dict[str, Any]):
102+
def make_pretty_func(func_name: str, *args: Any, **kwargs: Any):
104103
f_sig = f"{func_name}("
105104
f_sig += ", ".join(str(a) for a in args)
106105
if len(kwargs) != 0:
@@ -129,14 +128,18 @@ def _test_uninspectable_func(
129128
"and is too troublesome to test for otherwise"
130129
)
131130
if func_name in [
131+
# 0d shapes
132132
"__bool__",
133133
"__int__",
134134
"__index__",
135135
"__float__",
136+
# x2 elements must be >=0
136137
"pow",
137138
"bitwise_left_shift",
138139
"bitwise_right_shift",
140+
# axis default invalid with 0d shapes
139141
"sort",
142+
# shape requirements
140143
*matrixy_names,
141144
]:
142145
pytest.skip(skip_msg)
@@ -176,15 +179,15 @@ def _test_uninspectable_func(
176179
kwargs: Dict[str, Any] = {
177180
p.name: v for p, v in param_to_value.items() if p.kind == Parameter.KEYWORD_ONLY
178181
}
179-
f_func = make_pretty_func(func_name, args, kwargs)
182+
f_func = make_pretty_func(func_name, *args, **kwargs)
180183
note(f"trying {f_func}")
181184
func(*args, **kwargs)
182185

183186

184187
def _test_func_signature(func: Callable, stub: FunctionType, array=None):
185188
stub_sig = signature(stub)
186189
# If testing against array, ignore 'self' arg in stub as it won't be present
187-
# in func (which should be an array method).
190+
# in func (which should be a method).
188191
if array is not None:
189192
stub_params = list(stub_sig.parameters.values())
190193
del stub_params[0]

0 commit comments

Comments
 (0)