@@ -95,19 +95,19 @@ def test_mutator_descriptors():
95
95
with pytest .raises (TypeError ) as excinfo :
96
96
m .fixed_mutator_r (zc )
97
97
assert (
98
- '(arg0: typing.Annotated[numpy.typing.ArrayLike, numpy.float32, "[5, 6]",'
98
+ '(arg0: typing.Annotated[numpy.typing.NDArray[ numpy.float32] , "[5, 6]",'
99
99
' "flags.writeable", "flags.c_contiguous"]) -> None' in str (excinfo .value )
100
100
)
101
101
with pytest .raises (TypeError ) as excinfo :
102
102
m .fixed_mutator_c (zr )
103
103
assert (
104
- '(arg0: typing.Annotated[numpy.typing.ArrayLike, numpy.float32, "[5, 6]",'
104
+ '(arg0: typing.Annotated[numpy.typing.NDArray[ numpy.float32] , "[5, 6]",'
105
105
' "flags.writeable", "flags.f_contiguous"]) -> None' in str (excinfo .value )
106
106
)
107
107
with pytest .raises (TypeError ) as excinfo :
108
108
m .fixed_mutator_a (np .array ([[1 , 2 ], [3 , 4 ]], dtype = "float32" ))
109
109
assert (
110
- '(arg0: typing.Annotated[numpy.typing.ArrayLike, numpy.float32, "[5, 6]", "flags.writeable"]) -> None'
110
+ '(arg0: typing.Annotated[numpy.typing.NDArray[ numpy.float32] , "[5, 6]", "flags.writeable"]) -> None'
111
111
in str (excinfo .value )
112
112
)
113
113
zr .flags .writeable = False
@@ -202,7 +202,7 @@ def test_negative_stride_from_python(msg):
202
202
msg (excinfo .value )
203
203
== """
204
204
double_threer(): incompatible function arguments. The following argument types are supported:
205
- 1. (arg0: typing.Annotated[numpy.typing.ArrayLike, numpy.float32, "[1, 3]", "flags.writeable"]) -> None
205
+ 1. (arg0: typing.Annotated[numpy.typing.NDArray[ numpy.float32] , "[1, 3]", "flags.writeable"]) -> None
206
206
207
207
Invoked with: """
208
208
+ repr (np .array ([5.0 , 4.0 , 3.0 ], dtype = "float32" ))
@@ -214,7 +214,7 @@ def test_negative_stride_from_python(msg):
214
214
msg (excinfo .value )
215
215
== """
216
216
double_threec(): incompatible function arguments. The following argument types are supported:
217
- 1. (arg0: typing.Annotated[numpy.typing.ArrayLike, numpy.float32, "[3, 1]", "flags.writeable"]) -> None
217
+ 1. (arg0: typing.Annotated[numpy.typing.NDArray[ numpy.float32] , "[3, 1]", "flags.writeable"]) -> None
218
218
219
219
Invoked with: """
220
220
+ repr (np .array ([7.0 , 4.0 , 1.0 ], dtype = "float32" ))
@@ -818,3 +818,22 @@ def test_custom_operator_new():
818
818
o = m .CustomOperatorNew ()
819
819
np .testing .assert_allclose (o .a , 0.0 )
820
820
np .testing .assert_allclose (o .b .diagonal (), 1.0 )
821
+
822
+
823
+ def test_arraylike_signature (doc ):
824
+ assert doc (m .round_trip_vector ) == (
825
+ 'round_trip_vector(arg0: typing.Annotated[numpy.typing.ArrayLike, numpy.float32, "[m, 1]"])'
826
+ ' -> typing.Annotated[numpy.typing.NDArray[numpy.float32], "[m, 1]"]'
827
+ )
828
+ assert doc (m .round_trip_dense ) == (
829
+ 'round_trip_dense(arg0: typing.Annotated[numpy.typing.ArrayLike, numpy.float32, "[m, n]"])'
830
+ ' -> typing.Annotated[numpy.typing.NDArray[numpy.float32], "[m, n]"]'
831
+ )
832
+ assert doc (m .round_trip_dense_ref ) == (
833
+ 'round_trip_dense_ref(arg0: typing.Annotated[numpy.typing.NDArray[numpy.float32], "[m, n]", "flags.writeable", "flags.c_contiguous"])'
834
+ ' -> typing.Annotated[numpy.typing.NDArray[numpy.float32], "[m, n]", "flags.writeable", "flags.c_contiguous"]'
835
+ )
836
+ m .round_trip_vector ([1.0 , 2.0 ])
837
+ m .round_trip_dense ([[1.0 , 2.0 ], [3.0 , 4.0 ]])
838
+ with pytest .raises (TypeError , match = "incompatible function arguments" ):
839
+ m .round_trip_dense_ref ([[1.0 , 2.0 ], [3.0 , 4.0 ]])
0 commit comments