Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed array_t type hint #5353

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/pybind11/numpy.h
Original file line number Diff line number Diff line change
Expand Up @@ -2090,7 +2090,7 @@ vectorize_helper<Func, Return, Args...> vectorize_extractor(const Func &f, Retur
template <typename T, int Flags>
struct handle_type_name<array_t<T, Flags>> {
static constexpr auto name
= const_name("numpy.ndarray[") + npy_format_descriptor<T>::name + const_name("]");
= const_name("numpy.typing.NDArray[") + npy_format_descriptor<T>::name + const_name("]");
};

PYBIND11_NAMESPACE_END(detail)
Expand Down
20 changes: 10 additions & 10 deletions tests/test_numpy_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,13 +320,13 @@ def test_overload_resolution(msg):
msg(excinfo.value)
== """
overloaded(): incompatible function arguments. The following argument types are supported:
1. (arg0: numpy.ndarray[numpy.float64]) -> str
2. (arg0: numpy.ndarray[numpy.float32]) -> str
3. (arg0: numpy.ndarray[numpy.int32]) -> str
4. (arg0: numpy.ndarray[numpy.uint16]) -> str
5. (arg0: numpy.ndarray[numpy.int64]) -> str
6. (arg0: numpy.ndarray[numpy.complex128]) -> str
7. (arg0: numpy.ndarray[numpy.complex64]) -> str
1. (arg0: numpy.typing.NDArray[numpy.float64]) -> str
2. (arg0: numpy.typing.NDArray[numpy.float32]) -> str
3. (arg0: numpy.typing.NDArray[numpy.int32]) -> str
4. (arg0: numpy.typing.NDArray[numpy.uint16]) -> str
5. (arg0: numpy.typing.NDArray[numpy.int64]) -> str
6. (arg0: numpy.typing.NDArray[numpy.complex128]) -> str
7. (arg0: numpy.typing.NDArray[numpy.complex64]) -> str

Invoked with: 'not an array'
"""
Expand All @@ -342,8 +342,8 @@ def test_overload_resolution(msg):
assert m.overloaded3(np.array([1], dtype="intc")) == "int"
expected_exc = """
overloaded3(): incompatible function arguments. The following argument types are supported:
1. (arg0: numpy.ndarray[numpy.int32]) -> str
2. (arg0: numpy.ndarray[numpy.float64]) -> str
1. (arg0: numpy.typing.NDArray[numpy.int32]) -> str
2. (arg0: numpy.typing.NDArray[numpy.float64]) -> str

Invoked with: """

Expand Down Expand Up @@ -527,7 +527,7 @@ def test_index_using_ellipsis():
],
)
def test_format_descriptors_for_floating_point_types(test_func):
assert "numpy.ndarray[numpy.float" in test_func.__doc__
assert "numpy.typing.NDArray[numpy.float" in test_func.__doc__


@pytest.mark.parametrize("forcecast", [False, True])
Expand Down
2 changes: 1 addition & 1 deletion tests/test_numpy_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def test_complex_array():
def test_signature(doc):
assert (
doc(m.create_rec_nested)
== "create_rec_nested(arg0: int) -> numpy.ndarray[NestedStruct]"
== "create_rec_nested(arg0: int) -> numpy.typing.NDArray[NestedStruct]"
)


Expand Down
10 changes: 5 additions & 5 deletions tests/test_numpy_vectorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def test_docs(doc):
assert (
doc(m.vectorized_func)
== """
vectorized_func(arg0: numpy.ndarray[numpy.int32], arg1: numpy.ndarray[numpy.float32], arg2: numpy.ndarray[numpy.float64]) -> object
vectorized_func(arg0: numpy.typing.NDArray[numpy.int32], arg1: numpy.typing.NDArray[numpy.float32], arg2: numpy.typing.NDArray[numpy.float64]) -> object
"""
)

Expand Down Expand Up @@ -212,12 +212,12 @@ def test_passthrough_arguments(doc):
+ ", ".join(
[
"arg0: float",
"arg1: numpy.ndarray[numpy.float64]",
"arg2: numpy.ndarray[numpy.float64]",
"arg3: numpy.ndarray[numpy.int32]",
"arg1: numpy.typing.NDArray[numpy.float64]",
"arg2: numpy.typing.NDArray[numpy.float64]",
"arg3: numpy.typing.NDArray[numpy.int32]",
"arg4: int",
"arg5: m.numpy_vectorize.NonPODClass",
"arg6: numpy.ndarray[numpy.float64]",
"arg6: numpy.typing.NDArray[numpy.float64]",
]
)
+ ") -> object"
Expand Down