-
Notifications
You must be signed in to change notification settings - Fork 84
docs: add typing to commons #1054
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1b0d835
Add strict type-linting for commons
ec78d71
Add nptyping
e41220c
Add typing extensions
8ed1c4f
Add types to formulas
fc6bd89
Add types to misc
2206364
Add types to rates
54c25fd
Correct marginal rate calculation
c32fac4
Fix switch type annotation
4e07f30
Do not use slashes in .gitignore
13c954e
Sort .gitignore
def6bf0
Bump minor to 35.6.0
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,22 +1,22 @@ | ||
| .venv | ||
| .project | ||
| .spyderproject | ||
| .pydevproject | ||
| .vscode | ||
| .settings/ | ||
| .vscode/ | ||
| build/ | ||
| dist/ | ||
| doc/ | ||
| *.egg-info | ||
| *.mo | ||
| *.pyc | ||
| *~ | ||
| /cover | ||
| /.coverage | ||
| /tags | ||
| .tags* | ||
| .coverage | ||
| .mypy_cache | ||
| .noseids | ||
| .project | ||
| .pydevproject | ||
| .pytest_cache | ||
| .mypy_cache | ||
| .settings | ||
| .spyderproject | ||
| .tags* | ||
| .venv | ||
| .vscode | ||
| .vscode | ||
| build | ||
| cover | ||
| dist | ||
| doc | ||
| performance.json | ||
| tags |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| """Data types and protocols used by OpenFisca Core. | ||
|
|
||
| The type definitions included in this sub-package are intented for | ||
| contributors, to help them better understand and document contracts | ||
| and expected behaviours. | ||
|
|
||
| Official Public API: | ||
| * ``ArrayLike`` | ||
| * :attr:`.ArrayType` | ||
|
|
||
| Note: | ||
| How imports are being used today:: | ||
|
|
||
| from openfisca_core.types import * # Bad | ||
| from openfisca_core.types.data_types.arrays import ArrayLike # Bad | ||
|
|
||
|
|
||
| The previous examples provoke cyclic dependency problems, that prevents us | ||
| from modularizing the different components of the library, so as to make | ||
| them easier to test and to maintain. | ||
|
|
||
| How could them be used after the next major release:: | ||
|
|
||
| from openfisca_core.types import ArrayLike | ||
|
|
||
| ArrayLike # Good: import types as publicly exposed | ||
bonjourmauko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| .. seealso:: `PEP8#Imports`_ and `OpenFisca's Styleguide`_. | ||
|
|
||
| .. _PEP8#Imports: | ||
| https://www.python.org/dev/peps/pep-0008/#imports | ||
|
|
||
| .. _OpenFisca's Styleguide: | ||
| https://github.com/openfisca/openfisca-core/blob/master/STYLEGUIDE.md | ||
|
|
||
| """ | ||
|
|
||
| # Official Public API | ||
|
|
||
| from .data_types import ( # noqa: F401 | ||
| ArrayLike, | ||
| ArrayType, | ||
| ) | ||
|
|
||
| __all__ = ["ArrayLike", "ArrayType"] | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from .arrays import ArrayLike, ArrayType # noqa: F401 |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| from typing import Sequence, TypeVar, Union | ||
|
|
||
| from nptyping import types, NDArray as ArrayType | ||
|
|
||
| import numpy | ||
|
|
||
| T = TypeVar("T", bool, bytes, float, int, object, str) | ||
|
|
||
| types._ndarray_meta._Type = Union[type, numpy.dtype, TypeVar] | ||
|
|
||
| ArrayLike = Union[ArrayType[T], Sequence[T]] | ||
| """:obj:`typing.Generic`: Type of any castable to :class:`numpy.ndarray`. | ||
|
|
||
| These include any :obj:`numpy.ndarray` and sequences (like | ||
| :obj:`list`, :obj:`tuple`, and so on). | ||
|
|
||
| Examples: | ||
| >>> ArrayLike[float] | ||
| typing.Union[numpy.ndarray, typing.Sequence[float]] | ||
|
|
||
| >>> ArrayLike[str] | ||
| typing.Union[numpy.ndarray, typing.Sequence[str]] | ||
|
|
||
| Note: | ||
| It is possible since numpy version 1.21 to specify the type of an | ||
| array, thanks to `numpy.typing.NDArray`_:: | ||
|
|
||
| from numpy.typing import NDArray | ||
| NDArray[numpy.float64] | ||
|
|
||
| `mypy`_ provides `duck type compatibility`_, so an :obj:`int` is | ||
| considered to be valid whenever a :obj:`float` is expected. | ||
|
|
||
| Todo: | ||
| * Refactor once numpy version >= 1.21 is used. | ||
|
|
||
| .. versionadded:: 35.5.0 | ||
|
|
||
| .. versionchanged:: 35.6.0 | ||
| Moved to :mod:`.types` | ||
|
|
||
| .. _mypy: | ||
| https://mypy.readthedocs.io/en/stable/ | ||
|
|
||
| .. _duck type compatibility: | ||
| https://mypy.readthedocs.io/en/stable/duck_type_compatibility.html | ||
|
|
||
| .. _numpy.typing.NDArray: | ||
| https://numpy.org/doc/stable/reference/typing.html#numpy.typing.NDArray | ||
|
|
||
| """ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.