From cf51d9ea38095f32f09ff206e3261b6d88c3dda7 Mon Sep 17 00:00:00 2001 From: jf nz Date: Sat, 12 Sep 2026 23:51:20 +0000 Subject: [PATCH] Document docstrings for classes created with make_class --- docs/examples.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/examples.md b/docs/examples.md index f48b848bd..36b167e73 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -745,6 +745,17 @@ True ``` +To give the generated class a docstring, pass `__doc__` in the `class_body` argument: + +```{doctest} +>>> C = make_class("C", ["x", "y"], class_body={"__doc__": "A pair of values."}) +>>> C.__doc__ +'A pair of values.' +``` + +You can also assign to `C.__doc__` after creating the class. +Both approaches make the docstring available to `help(C)`. + You can still have power over the attributes if you pass a dictionary of name: {func}`~attrs.field` mappings and can pass the same arguments as you can to `@attrs.define`: ```{doctest}