-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from adamboche/autoapi
Autoapi
- Loading branch information
Showing
9 changed files
with
90 additions
and
62 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,5 +1,5 @@ | ||
[bumpversion] | ||
current_version = 0.1.3 | ||
current_version = 0.1.4 | ||
commit = True | ||
tag = True | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
sphinx>=1.3 | ||
sphinx-rtd-theme | ||
sphinx-autodoc-typehints | ||
-e . |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,53 @@ | ||
from ._core import Union | ||
import typing as t | ||
|
||
__version__ = "__version__ = 0.1.3" | ||
import marshmallow | ||
import marshmallow.exceptions | ||
|
||
|
||
class Union(marshmallow.fields.Field): | ||
"""Field that accepts any one of multiple fields. | ||
Each argument will be tried until one succeeds. | ||
Args: | ||
fields: The list of candidate fields to try. | ||
reverse_serialize_candidates: Whether to try the candidates in reverse order when | ||
serializing. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
fields: t.List[marshmallow.fields.Field], | ||
reverse_serialize_candidates: bool = False, | ||
*args, | ||
**kwargs | ||
): | ||
self._candidate_fields = fields | ||
self._reverse_serialize_candidates = reverse_serialize_candidates | ||
super().__init__(*args, **kwargs) | ||
|
||
def _serialize(self, value, attr, obj, **kwargs): | ||
errors = [] | ||
|
||
fields = self._candidate_fields | ||
if self._reverse_serialize_candidates: | ||
fields = reversed(fields) | ||
|
||
for candidate_field in fields: | ||
try: | ||
return candidate_field._serialize(value, attr, obj, **kwargs) | ||
except marshmallow.exceptions.ValidationError as e: | ||
errors.append(e.messages) | ||
raise marshmallow.exceptions.ValidationError(message=errors, field_name=attr) | ||
|
||
def _deserialize(self, value, attr, obj, **kwargs): | ||
errors = [] | ||
for candidate_field in self._candidate_fields: | ||
try: | ||
return candidate_field._deserialize(value, attr, obj, **kwargs) | ||
except marshmallow.exceptions.ValidationError as e: | ||
errors.append(e.messages) | ||
raise marshmallow.exceptions.ValidationError(message=errors, field_name=attr) | ||
|
||
|
||
__version__ = "__version__ = 0.1.4" |
This file was deleted.
Oops, something went wrong.
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