Skip to content

Commit

Permalink
Fix order of documenting attributes and parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
izxxr committed Mar 2, 2024
1 parent 13b2800 commit b1debae
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 80 deletions.
20 changes: 10 additions & 10 deletions oblate/fields/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,6 @@ class Field(Generic[RawValueT, FinalValueT]):
raw value type i.e the type of raw value which will be deserialized to final
value and the type of deserialized value.
Attributes
----------
ERR_FIELD_REQUIRED:
Error code raised when a required field is not given in raw data.
ERR_NONE_DISALLOWED:
Error code raised when a field with ``none=False`` is given a value of ``None``.
ERR_VALIDATION_FAILED:
Error code raised when a validator fails for a field without an explicit
error message.
Parameters
----------
none: :class:`bool`
Expand Down Expand Up @@ -117,6 +107,16 @@ class Field(Generic[RawValueT, FinalValueT]):
data_key: :class:`str`
A shorthand parameter to control the value of both ``load_key`` and ``dump_key``
parameters.
Attributes
----------
ERR_FIELD_REQUIRED:
Error code raised when a required field is not given in raw data.
ERR_NONE_DISALLOWED:
Error code raised when a field with ``none=False`` is given a value of ``None``.
ERR_VALIDATION_FAILED:
Error code raised when a validator fails for a field without an explicit
error message.
"""
ERR_FIELD_REQUIRED = 'field.field_required'
ERR_NONE_DISALLOWED = 'field.none_disallowed'
Expand Down
10 changes: 5 additions & 5 deletions oblate/fields/nesting.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ class Book(oblate.Schema):
Passing :class:`Schema` instances directly is now supported other than raw data.
Attributes
----------
ERR_INVALID_DATATYPE:
Error code raised when invalid data type is given in raw data.
Parameters
----------
schema_cls: Type[:class:`Schema`]
Expand All @@ -86,6 +81,11 @@ class Book(oblate.Schema):
``schema_cls``. If a ``schema_cls`` instance is passed, this parameter is ignored.
.. versionadded:: 1.1
Attributes
----------
ERR_INVALID_DATATYPE:
Error code raised when invalid data type is given in raw data.
"""
ERR_INVALID_DATATYPE = 'object.invalid_datatype'

Expand Down
61 changes: 30 additions & 31 deletions oblate/fields/primitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ class String(Field[str, str]):
This class is a subclass of :class:`Field` and supports the features
documented in that class.
Parameters
----------
strict: :class:`bool`
Whether to only allow string data types. If this is set to False,
any value is type casted to string. Defaults to True.
Attributes
----------
ERR_INVALID_DATATYPE:
Error code raised when invalid data type is given in raw data.
ERR_COERCION_FAILED:
Error code raised when strict mode is disabled and given raw value
cannot be converted to relevant data type.
Parameters
----------
strict: :class:`bool`
Whether to only allow string data types. If this is set to False,
any value is type casted to string. Defaults to True.
"""
ERR_INVALID_DATATYPE = 'string.invalid_datatype'

Expand Down Expand Up @@ -89,19 +89,19 @@ class Integer(Field[int, int]):
This class is a subclass of :class:`Field` and supports the features
documented in that class.
Parameters
----------
strict: :class:`bool`
Whether to only allow integer data types. If this is set to False,
any integer-castable value is type casted to integer. Defaults to True.
Attributes
----------
ERR_INVALID_DATATYPE:
Error code raised when invalid data type is given in raw data.
ERR_COERCION_FAILED:
Error code raised when strict mode is disabled and given raw value
cannot be converted to relevant data type.
Parameters
----------
strict: :class:`bool`
Whether to only allow integer data types. If this is set to False,
any integer-castable value is type casted to integer. Defaults to True.
"""
ERR_INVALID_DATATYPE = 'integer.invalid_datatype'
ERR_COERCION_FAILED = 'integer.coercion_failed'
Expand Down Expand Up @@ -142,19 +142,6 @@ class Boolean(Field[bool, bool]):
This class is a subclass of :class:`Field` and supports the features
documented in that class.
Attributes
----------
TRUE_VALUES: Tuple[:class:`str`, ...]
The true values used when strict validation is disabled.
FALSE_VALUES: Tuple[:class:`str`, ...]
The false values used when strict validation is disabled.
ERR_INVALID_DATATYPE:
Error code raised when invalid data type is given in raw data.
ERR_COERCION_FAILED:
Error code raised when strict mode is disabled and given raw value
cannot be converted to relevant data type.
Parameters
----------
true_values: Sequence[:class:`str`]
Expand All @@ -167,6 +154,18 @@ class Boolean(Field[bool, bool]):
when :ref:`strict validation <guide-fields-strict-mode>` is disabled.
Defaults to :attr:`.FALSE_VALUES` if not provided.
Attributes
----------
TRUE_VALUES: Tuple[:class:`str`, ...]
The true values used when strict validation is disabled.
FALSE_VALUES: Tuple[:class:`str`, ...]
The false values used when strict validation is disabled.
ERR_INVALID_DATATYPE:
Error code raised when invalid data type is given in raw data.
ERR_COERCION_FAILED:
Error code raised when strict mode is disabled and given raw value
cannot be converted to relevant data type.
"""
TRUE_VALUES: Sequence[str] = (
'TRUE', 'True', 'true',
Expand Down Expand Up @@ -231,19 +230,19 @@ class Float(Field[float, float]):
This class is a subclass of :class:`Field` and supports the features
documented in that class.
Parameters
----------
strict: :class:`bool`
Whether to only allow float data types. If this is set to False,
any float-castable value is type casted to float. Defaults to True.
Attributes
----------
ERR_INVALID_DATATYPE:
Error code raised when invalid data type is given in raw data.
ERR_COERCION_FAILED:
Error code raised when strict mode is disabled and given raw value
cannot be converted to relevant data type.
Parameters
----------
strict: :class:`bool`
Whether to only allow float data types. If this is set to False,
any float-castable value is type casted to float. Defaults to True.
"""
ERR_INVALID_DATATYPE = 'float.invalid_datatype'
ERR_COERCION_FAILED = 'float.coercion_failed'
Expand Down
50 changes: 26 additions & 24 deletions oblate/fields/structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ class Dict(_BaseStructField[DictT[KT, VT], DictT[KT, VT]]):
.. versionadded:: 1.1
Parameters
----------
key_tp:
The type of key of dictionary. This parameter supports
passing :ref:`type expressions <guide-type-validation>`.
value_tp:
The type of value of dictionary. This parameter supports
passing :ref:`type expressions <guide-type-validation>`.
Attributes
----------
ERR_INVALID_DATATYPE:
Expand All @@ -96,13 +105,6 @@ class Dict(_BaseStructField[DictT[KT, VT], DictT[KT, VT]]):
Error raised when the type validation fails. In this error's context,
:attr:`ErrorContext.metadata` has a key ``type_validation_fail_errors``
which is a list of error messages.
Parameters
----------
key_tp:
The type of key of dictionary.
value_tp:
The type of value of dictionary.
"""
_struct_name = 'dict'
_friendly_struct_name = 'dictionary'
Expand Down Expand Up @@ -142,6 +144,11 @@ class TypedDict(_BaseStructField[TD, TD]):
.. versionadded:: 1.1
Parameters
----------
typed_dict: :class:`typing.TypedDict`
The typed dictionary to validate from.
Attributes
----------
ERR_INVALID_DATATYPE:
Expand All @@ -150,11 +157,6 @@ class TypedDict(_BaseStructField[TD, TD]):
Error raised when the type validation fails. In this error's context,
:attr:`ErrorContext.metadata` has a key ``type_validation_fail_errors``
which is a list of error messages.
Parameters
----------
typed_dict: :class:`typing.TypedDict`
The typed dictionary to validate from.
"""
_struct_name = 'typed_dict'
_friendly_struct_name = 'dictionary'
Expand Down Expand Up @@ -184,6 +186,12 @@ class List(_BaseStructField[ListT[KT], ListT[KT]]):
.. versionadded:: 1.1
Parameters
----------
type:
The type of list elements. This parameter corresponds to ``T``
in ``typing.List[T]`` and supports :ref:`type expressions <guide-type-validation>`.
Attributes
----------
ERR_INVALID_DATATYPE:
Expand All @@ -192,12 +200,6 @@ class List(_BaseStructField[ListT[KT], ListT[KT]]):
Error raised when the type validation fails. In this error's context,
:attr:`ErrorContext.metadata` has a key ``type_validation_fail_errors``
which is a list of error messages.
Parameters
----------
type:
The type of list elements. This parameter corresponds to ``T``
in ``typing.List[T]``.
"""
_struct_name = 'list'
_friendly_struct_name = 'list'
Expand Down Expand Up @@ -226,6 +228,12 @@ class Set(_BaseStructField[SetT[KT], SetT[KT]]):
.. versionadded:: 1.1
Parameters
----------
type:
The type of set elements. This parameter corresponds to ``T``
in ``typing.Set[T]`` and supports :ref:`type expressions <guide-type-validation>`.
Attributes
----------
ERR_INVALID_DATATYPE:
Expand All @@ -234,12 +242,6 @@ class Set(_BaseStructField[SetT[KT], SetT[KT]]):
Error raised when the type validation fails. In this error's context,
:attr:`ErrorContext.metadata` has a key ``type_validation_fail_errors``
which is a list of error messages.
Parameters
----------
type:
The type of set elements. This parameter corresponds to ``T``
in ``typing.Set[T]``.
"""
_struct_name = 'set'
_friendly_struct_name = 'set'
Expand Down
26 changes: 16 additions & 10 deletions oblate/fields/typings.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ class Literal(Field[_T, _T]):
.. versionadded:: 1.1
Attributes
----------
ERR_INVALID_VALUE:
Error raised when the given value is not from the provided literal value.
Parameters
----------
*values:
The literal values.
Attributes
----------
ERR_INVALID_VALUE:
Error raised when the given value is not from the provided literal value.
"""
ERR_INVALID_VALUE = 'literal.invalid_value'

Expand Down Expand Up @@ -110,15 +110,15 @@ class Union(Field[_T, _T]):
.. versionadded:: 1.1
Attributes
----------
ERR_INVALID_VALUE:
Error raised when the given value is not from the provided types.
Parameters
----------
*types: :class:`type`
The list of types to accept.
Attributes
----------
ERR_INVALID_VALUE:
Error raised when the given value is not from the provided types.
"""
ERR_INVALID_VALUE = 'union.invalid_value'

Expand Down Expand Up @@ -164,6 +164,12 @@ class TypeExpr(Field[_T, _T]):
expr:
The type expression that should be used to validate the type of
given value.
Attributes
----------
ERR_TYPE_VALIDATION_FAILED:
Error raised when the given value does not pass type
validation.
"""
ERR_TYPE_VALIDATION_FAILED = 'type_expr.type_validation_failed'

Expand Down

0 comments on commit b1debae

Please sign in to comment.