Removed unused elements from unions, e.g. Float[ArrayLike, ...] will no longer include Float[np.bool, ...].

This commit is contained in:
Patrick Kidger
2023-11-27 09:50:02 -08:00
parent baffbef5ca
commit 80a99568f7
2 changed files with 10 additions and 6 deletions
+10
View File
@@ -498,6 +498,16 @@ def _make_array(array_type, dim_str, dtypes, name):
return array_type
else:
return _not_made
elif array_type is np.bool_:
if _check_scalar("bool", dtypes, dims):
return array_type
else:
return _not_made
elif array_type is np.generic or array_type is np.number:
if _check_scalar("", dtypes, dims):
return array_type
else:
return _not_made
if issubclass(array_type, AbstractArray):
if dtypes is _any_dtype:
dtypes = array_type.dtypes
-6
View File
@@ -496,22 +496,18 @@ def test_arraylike(typecheck, getkey):
assert set(get_args(floatlike1)) == {
Float32[Array, ""],
Float32[np.ndarray, ""],
Float32[np.bool_, ""],
Float32[np.number, ""],
float,
}
assert set(get_args(floatlike2)) == {
Float[Array, ""],
Float[np.ndarray, ""],
Float[np.bool_, ""],
Float[np.number, ""],
float,
}
assert set(get_args(floatlike3)) == {
Float32[Array, "4"],
Float32[np.ndarray, "4"],
Float32[np.bool_, "4"],
Float32[np.number, "4"],
}
shaped1 = Shaped[ArrayLike, ""]
@@ -531,8 +527,6 @@ def test_arraylike(typecheck, getkey):
assert set(get_args(shaped2)) == {
Shaped[Array, "4"],
Shaped[np.ndarray, "4"],
Shaped[np.bool_, "4"],
Shaped[np.number, "4"],
}