From 73e39ca557c88d65b56512d6222f6c6e1109e57c Mon Sep 17 00:00:00 2001 From: Marcelo Trylesinski Date: Mon, 12 Jun 2023 13:29:58 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Add=20docstrings=20for=20`functi?= =?UTF-8?q?onal=5Fserializers.py`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pydantic/functional_serializers.py | 12 ++++++------ pyproject.toml | 1 - 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/pydantic/functional_serializers.py b/pydantic/functional_serializers.py index f8d068a3d79..48534dff3ae 100644 --- a/pydantic/functional_serializers.py +++ b/pydantic/functional_serializers.py @@ -1,3 +1,4 @@ +"""This module contains related classes and functions for serialization.""" from __future__ import annotations from functools import partialmethod @@ -56,8 +57,8 @@ class WrapSerializer: Attributes: func: The function to be wrapped. - return_type: Optional return type for the function, if omitted it will be inferred from the type annotation. - when_used: Determines the serializer will be used for serialization. Accepts a string with values `'always'`, + return_type: The return type for the function, if omitted it will be inferred from the type annotation. + when_used: Determines when this serializer should be used. Accepts a string with values `'always'`, `'unless-none'`, `'json'`, and `'json-unless-none'`. Defaults to 'always'. """ @@ -203,15 +204,14 @@ def model_serializer( ) -> Callable[[Any], Any]: """Decorate a function which will be called to serialize the model. - (`when_used` is not permitted here since it makes no sense.) - Args: __f: The function to be decorated. mode: The serialization mode. `'plain'` means the function will be called instead of the default serialization logic, `'wrap'` means the function will be called with an argument to optionally call the default serialization logic. - when_used: Determines the serializer will be be used for serialization. - return_type: Optional return type for the function, if omitted it will be inferred from the type annotation. + when_used: Determines when this serializer should be used. Accepts a string with values `'always'`, + `'unless-none'`, `'json'`, `'json-unless-none'`. Defaults to `'always'`. + return_type: The return type for the function, if omitted it will be inferred from the type annotation. Returns: A decorator that can be used to decorate a function to be used as a model serializer. diff --git a/pyproject.toml b/pyproject.toml index 8f47f4ff20a..5ab51df3e81 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -178,7 +178,6 @@ convention = "google" 'pydantic/deprecated/*' = ['D'] 'pydantic/fields.py' = ['D'] 'pydantic/functional_validators.py' = ['D'] -'pydantic/functional_serializers.py' = ['D'] 'pydantic/json_schema.py' = ['D'] 'pydantic/main.py' = ['D'] 'pydantic/mypy.py' = ['D']