Skip to content
This repository has been archived by the owner on Apr 17, 2024. It is now read-only.

Commit

Permalink
feat: class docstring overrides default description from __schema__, f…
Browse files Browse the repository at this point in the history
  • Loading branch information
apirogov committed Sep 27, 2022
1 parent fcb136d commit 472259d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/phantom/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ def __modify_schema__(cls, field_schema: dict) -> None:
:func:`__schema__() <phantom.Phantom.__schema__>` to provide custom schema
representations for phantom types.
"""
schema = cls.__schema__()
if cls.__doc__ is not None:
schema["description"] = cls.__doc__
field_schema.update(
{key: value for key, value in cls.__schema__().items() if value is not None}
{key: value for key, value in schema.items() if value is not None}
)

@classmethod
Expand All @@ -44,6 +47,9 @@ def __schema__(cls) -> Schema:
for more information. This hook differs to pydantic's ``__modify_schema__()``
and expects subclasses to instantiate new dicts instead of mutating a given one.
Note that the docstring attached to a phantom type class, if present,
will override any description that is defined in `__schema__()`.
Example:
.. code-block:: python
Expand Down

0 comments on commit 472259d

Please sign in to comment.