@@ -19,6 +19,11 @@ m: np.timedelta64
1919U : np .str_
2020S : np .bytes_
2121V : np .void
22+ O : np .object_ # cannot exists at runtime
23+
24+ array_nd : np .ndarray [Any , Any ]
25+ array_0d : np .ndarray [tuple [()], Any ]
26+ array_2d_2x2 : np .ndarray [tuple [Literal [2 ], Literal [2 ]], Any ]
2227
2328assert_type (c8 .real , np .float32 )
2429assert_type (c8 .imag , np .float32 )
@@ -156,3 +161,27 @@ assert_type(f8.__ceil__(), int)
156161assert_type (f8 .__floor__ (), int )
157162
158163assert_type (i8 .is_integer (), Literal [True ])
164+
165+ assert_type (O .real , np .object_ )
166+ assert_type (O .imag , np .object_ )
167+ assert_type (int (O ), int )
168+ assert_type (float (O ), float )
169+ assert_type (complex (O ), complex )
170+
171+ # These fail fail because of a mypy __new__ bug:
172+ # https://github.com/python/mypy/issues/15182
173+ # According to the typing spec, the following statements are valid, see
174+ # https://typing.readthedocs.io/en/latest/spec/constructors.html#new-method
175+
176+ # assert_type(np.object_(), None)
177+ # assert_type(np.object_(None), None)
178+ # assert_type(np.object_(array_nd), np.ndarray[Any, np.dtype[np.object_]])
179+ # assert_type(np.object_([]), npt.NDArray[np.object_])
180+ # assert_type(np.object_(()), npt.NDArray[np.object_])
181+ # assert_type(np.object_(range(4)), npt.NDArray[np.object_])
182+ # assert_type(np.object_(+42), int)
183+ # assert_type(np.object_(1 / 137), float)
184+ # assert_type(np.object_('Developers! ' * (1 << 6)), str)
185+ # assert_type(np.object_(object()), object)
186+ # assert_type(np.object_({False, True, NotADirectoryError}), set[Any])
187+ # assert_type(np.object_({'spam': 'food', 'ham': 'food'}), dict[str, str])
0 commit comments