-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mauko Quiroga
committed
Aug 23, 2021
1 parent
102e9e0
commit f4713af
Showing
6 changed files
with
60 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,44 @@ | ||
"""Module's shared types. | ||
Todo: | ||
Note: | ||
* Refactor once numpy version >= 1.21 is used. | ||
It is possible since numpy version 1.21 to specify the type of an | ||
array, thanks to :class:`numpy.typing.mypy_plugin.NDArray`: | ||
""" | ||
from numpy.typing import NDArray | ||
NDArray[numpy.float64] | ||
... | ||
from typing import TYPE_CHECKING | ||
Also note that :module:`mypy` provides duck type compatibility, so an | ||
:obj:`int` is considered to be valid whenever an :obj:`float` is expected. | ||
if TYPE_CHECKING: | ||
from typing import Sequence, TypeVar, Union | ||
Attributes: | ||
import numpy | ||
_T (:obj:`typing.TypeVar`): | ||
A 'wildcard' type used by other types. | ||
"""'Wildcard' type used by other types.""" | ||
_T = TypeVar("_T", float, str) | ||
ArrayLike (:obj:`typing._GenericAlias`): | ||
The type of any object that can be coerced to a :obj:`numpy.array`. | ||
These include any :obj:`numpy.array` and 'sequence' (like | ||
:class:`list`, :class:`tuple`, and so on). | ||
"""Type of any object that can be casted to a :obj:`numpy.array`. | ||
Examples: | ||
These include any :obj:`numpy.array` and 'sequence' (like :class:`list`, | ||
:class:`tuple`, and so on). | ||
>>> ArrayLike[float] | ||
typing.Union[numpy.ndarray, typing.Sequence[float]] | ||
Note: | ||
>>> ArrayLike[str] | ||
typing.Union[numpy.ndarray, typing.Sequence[str]] | ||
It is possible since numpy version 1.21 to specify the type of an | ||
array, thanks to :class:`numpy.typing.mypy_plugin.NDArray`. | ||
Todo: | ||
Examples: | ||
* Refactor once numpy version >= 1.21 is used. | ||
""" | ||
|
||
>>> ArrayLike[float] | ||
typing.Union[numpy.ndarray, typing.Sequence[float]] | ||
from typing import Sequence, TypeVar, Union | ||
|
||
>>> from numpy.typing import NDArray | ||
>>> NDArray[numpy.float64] | ||
numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]] | ||
import numpy | ||
|
||
""" | ||
ArrayLike = Union[numpy.ndarray, Sequence[_T]] | ||
_T = TypeVar("_T", float, str) | ||
ArrayLike = Union[numpy.ndarray, Sequence[_T]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.