https://github.com/python/cpython/commit/d021b719ed87d4ce6e03913361564c1c79215123
commit: d021b719ed87d4ce6e03913361564c1c79215123
branch: 3.13
author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com>
committer: ericvsmith <ericvsm...@users.noreply.github.com>
date: 2025-04-13T16:53:40Z
summary:

[3.13] gh-132111: Document dataclasses.InitVar (GH-132446) (#132483)

gh-132111: Document dataclasses.InitVar (GH-132446)
(cherry picked from commit 281fc338fdf57ef119e213bf1b2c772261c359c1)

Co-authored-by: Tapeline <m...@tapeline.dev>

files:
M Doc/library/dataclasses.rst

diff --git a/Doc/library/dataclasses.rst b/Doc/library/dataclasses.rst
index 134ba0fa9b4b9f..47b2d559989696 100644
--- a/Doc/library/dataclasses.rst
+++ b/Doc/library/dataclasses.rst
@@ -347,6 +347,15 @@ Module contents
    Other attributes may exist, but they are private and must not be
    inspected or relied on.
 
+.. class:: InitVar
+
+   ``InitVar[T]`` type annotations describe variables that are :ref:`init-only
+   <dataclasses-init-only-variables>`. Fields annotated with :class:`!InitVar`
+   are considered pseudo-fields, and thus are neither returned by the
+   :func:`fields` function nor used in any way except adding them as
+   parameters to :meth:`~object.__init__` and an optional
+   :meth:`__post_init__`.
+
 .. function:: fields(class_or_instance)
 
    Returns a tuple of :class:`Field` objects that define the fields for this
@@ -595,8 +604,8 @@ Init-only variables
 
 Another place where :func:`@dataclass <dataclass>` inspects a type annotation 
is to
 determine if a field is an init-only variable.  It does this by seeing
-if the type of a field is of type ``dataclasses.InitVar``.  If a field
-is an ``InitVar``, it is considered a pseudo-field called an init-only
+if the type of a field is of type :class:`InitVar`.  If a field
+is an :class:`InitVar`, it is considered a pseudo-field called an init-only
 field.  As it is not a true field, it is not returned by the
 module-level :func:`fields` function.  Init-only fields are added as
 parameters to the generated :meth:`~object.__init__` method, and are passed to

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to