Skip to content

Commit

Permalink
TYP: Relax the return-type of np.vectorize (#20908)
Browse files Browse the repository at this point in the history
* MAINT: Relax the return-type of `np.vectorize`

* DOC: Add a note regarding a potential future mypy plugin for dealing with literal signatures

Co-authored-by: Bas van Beek <43369155+BvB93@users.noreply.github.com>
  • Loading branch information
charris and BvB93 committed Jan 28, 2022
1 parent d9df288 commit 8c74847
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion numpy/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3679,6 +3679,8 @@ class memmap(ndarray[_ShapeType, _DType_co]):
) -> Any: ...
def flush(self) -> None: ...

# TODO: Add a mypy plugin for managing functions whose output type is dependant
# on the literal value of some sort of signature (e.g. `einsum` and `vectorize`)
class vectorize:
pyfunc: Callable[..., Any]
cache: bool
Expand All @@ -3695,7 +3697,7 @@ class vectorize:
cache: bool = ...,
signature: None | str = ...,
) -> None: ...
def __call__(self, *args: Any, **kwargs: Any) -> NDArray[Any]: ...
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...

class poly1d:
@property
Expand Down
2 changes: 1 addition & 1 deletion numpy/typing/tests/data/reveal/lib_function_base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ reveal_type(vectorized_func.signature) # E: Union[None, builtins.str]
reveal_type(vectorized_func.otypes) # E: Union[None, builtins.str]
reveal_type(vectorized_func.excluded) # E: set[Union[builtins.int, builtins.str]]
reveal_type(vectorized_func.__doc__) # E: Union[None, builtins.str]
reveal_type(vectorized_func([1])) # E: ndarray[Any, dtype[Any]]
reveal_type(vectorized_func([1])) # E: Any
reveal_type(np.vectorize(int)) # E: vectorize
reveal_type(np.vectorize( # E: vectorize
int, otypes="i", doc="doc", excluded=(), cache=True, signature=None
Expand Down

0 comments on commit 8c74847

Please sign in to comment.