-
Notifications
You must be signed in to change notification settings - Fork 84
docs: improve commons module documentation #1055
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
9 commits
Select commit
Hold shift + click to select a range
39adeaf
Add tasks to lint the doc
5123590
Add config to lint documentation
fd64557
Add doc to commons module
d4267ef
Add doc to dummy
3650672
Add doc to formulas
f174657
Add doc to misc
212cf96
Add doc to rates
12afce0
Apply suggestions from code review
fd75c50
Bump patch to 35.5.5
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
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,28 +1,67 @@ | ||
| # Transitional imports to ensure non-breaking changes. | ||
| # Could be deprecated in the next major release. | ||
| # | ||
| # How imports are being used today: | ||
| # | ||
| # >>> from openfisca_core.module import symbol | ||
| # | ||
| # The previous example provokes cyclic dependency problems | ||
| # that prevent us from modularizing the different components | ||
| # of the library so to make them easier to test and to maintain. | ||
| # | ||
| # How could them be used after the next major release: | ||
| # | ||
| # >>> from openfisca_core import module | ||
| # >>> module.symbol() | ||
| # | ||
| # And for classes: | ||
| # | ||
| # >>> from openfisca_core.module import Symbol | ||
| # >>> Symbol() | ||
| # | ||
| # See: https://www.python.org/dev/peps/pep-0008/#imports | ||
| """Common tools for contributors and users. | ||
|
|
||
| from .dummy import Dummy # noqa: F401 | ||
| The tools in this sub-package are intended, to help both contributors | ||
| to OpenFisca Core and to country packages. | ||
|
|
||
| Official Public API: | ||
| * :func:`.apply_thresholds` | ||
| * :func:`.average_rate` | ||
| * :func:`.concat` | ||
| * :func:`.empty_clone` | ||
| * :func:`.marginal_rate` | ||
| * :func:`.stringify_array` | ||
| * :func:`.switch` | ||
|
|
||
| Deprecated: | ||
| * :class:`.Dummy` | ||
|
|
||
| Note: | ||
| The ``deprecated`` imports are transitional, in order to ensure non-breaking | ||
| changes, and could be removed from the codebase in the next | ||
| major release. | ||
|
|
||
| Note: | ||
| How imports are being used today:: | ||
|
|
||
| from openfisca_core.commons import * # Bad | ||
| from openfisca_core.commons.formulas import switch # Bad | ||
| from openfisca_core.commons.decorators import deprecated # Bad | ||
|
|
||
|
|
||
| The previous examples provoke cyclic dependency problems, that prevent us | ||
| from modularizing the different components of the library, which would make | ||
| them easier to test and to maintain. | ||
|
|
||
| How they could be used in a future release: | ||
|
|
||
| from openfisca_core import commons | ||
| from openfisca_core.commons import deprecated | ||
|
|
||
| deprecated() # Good: import classes as publicly exposed | ||
| commons.switch() # Good: use functions as publicly exposed | ||
|
|
||
| .. 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 .formulas import apply_thresholds, concat, switch # noqa: F401 | ||
| from .misc import empty_clone, stringify_array # noqa: F401 | ||
| from .rates import average_rate, marginal_rate # noqa: F401 | ||
|
|
||
| __all__ = ["apply_thresholds", "concat", "switch"] | ||
| __all__ = ["empty_clone", "stringify_array", *__all__] | ||
| __all__ = ["average_rate", "marginal_rate", *__all__] | ||
|
|
||
| # Deprecated | ||
|
|
||
| from .dummy import Dummy # noqa: F401 | ||
|
|
||
| __all__ = ["Dummy", *__all__] |
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 |
|---|---|---|
|
|
@@ -2,7 +2,13 @@ | |
|
|
||
|
|
||
| def empty_clone(original): | ||
| """Create a new empty instance of the same class of the original object. | ||
| """Creates an empty instance of the same class of the original object. | ||
|
|
||
| Args: | ||
| original: An object to clone. | ||
|
|
||
| Returns: | ||
| The cloned, empty, object. | ||
|
|
||
| Examples: | ||
| >>> Foo = type("Foo", (list,), {}) | ||
|
|
@@ -20,17 +26,25 @@ def empty_clone(original): | |
| """ | ||
|
|
||
| class Dummy(original.__class__): | ||
| """Dummy class for empty cloning.""" | ||
|
|
||
| def __init__(self) -> None: | ||
| pass | ||
| ... | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| new = Dummy() | ||
| new.__class__ = original.__class__ | ||
| return new | ||
|
|
||
|
|
||
| def stringify_array(array: numpy.ndarray) -> str: | ||
| """ | ||
| Generate a clean string representation of a NumPY array. | ||
| """Generates a clean string representation of a numpy array. | ||
|
|
||
| Args: | ||
| array: An array. | ||
|
|
||
| Returns: | ||
| :obj:`str`: | ||
| "None" if the ``array`` is None, the stringified ``array`` otherwise. | ||
|
|
||
| Examples: | ||
| >>> import numpy | ||
|
|
||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you agree, please do file an issue so other members of the community can eventually pick it.