From b1debae84e73dcea73a822643e9d371678ec8b56 Mon Sep 17 00:00:00 2001 From: Izhar Ahmad Date: Sat, 2 Mar 2024 09:50:26 +0500 Subject: [PATCH] Fix order of documenting attributes and parameters --- oblate/fields/base.py | 20 ++++++------- oblate/fields/nesting.py | 10 +++---- oblate/fields/primitive.py | 61 +++++++++++++++++++------------------- oblate/fields/structs.py | 50 ++++++++++++++++--------------- oblate/fields/typings.py | 26 +++++++++------- 5 files changed, 87 insertions(+), 80 deletions(-) diff --git a/oblate/fields/base.py b/oblate/fields/base.py index 004ce4e..6b35350 100644 --- a/oblate/fields/base.py +++ b/oblate/fields/base.py @@ -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` @@ -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' diff --git a/oblate/fields/nesting.py b/oblate/fields/nesting.py index f1877a8..d29bcdd 100644 --- a/oblate/fields/nesting.py +++ b/oblate/fields/nesting.py @@ -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`] @@ -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' diff --git a/oblate/fields/primitive.py b/oblate/fields/primitive.py index 1e39458..fd0c7e1 100644 --- a/oblate/fields/primitive.py +++ b/oblate/fields/primitive.py @@ -42,6 +42,12 @@ 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: @@ -49,12 +55,6 @@ class String(Field[str, str]): 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' @@ -89,6 +89,12 @@ 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: @@ -96,12 +102,6 @@ class Integer(Field[int, int]): 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' @@ -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`] @@ -167,6 +154,18 @@ class Boolean(Field[bool, bool]): when :ref:`strict validation ` 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', @@ -231,6 +230,12 @@ 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: @@ -238,12 +243,6 @@ class Float(Field[float, float]): 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' diff --git a/oblate/fields/structs.py b/oblate/fields/structs.py index 1336f48..b38ea5c 100644 --- a/oblate/fields/structs.py +++ b/oblate/fields/structs.py @@ -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 `. + value_tp: + The type of value of dictionary. This parameter supports + passing :ref:`type expressions `. + Attributes ---------- ERR_INVALID_DATATYPE: @@ -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' @@ -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: @@ -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' @@ -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 `. + Attributes ---------- ERR_INVALID_DATATYPE: @@ -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' @@ -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 `. + Attributes ---------- ERR_INVALID_DATATYPE: @@ -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' diff --git a/oblate/fields/typings.py b/oblate/fields/typings.py index 113ff35..a3e7806 100644 --- a/oblate/fields/typings.py +++ b/oblate/fields/typings.py @@ -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' @@ -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' @@ -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'