File tree 1 file changed +11
-2
lines changed 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -347,6 +347,15 @@ Module contents
347
347
Other attributes may exist, but they are private and must not be
348
348
inspected or relied on.
349
349
350
+ .. class :: InitVar
351
+
352
+ ``InitVar[T] `` type annotations describe variables that are :ref: `init-only
353
+ <dataclasses-init-only-variables>`. Fields annotated with :class: `!InitVar `
354
+ are considered pseudo-fields, and thus are neither returned by the
355
+ :func: `fields ` function nor used in any way except adding them as
356
+ parameters to :meth: `~object.__init__ ` and an optional
357
+ :meth: `__post_init__ `.
358
+
350
359
.. function :: fields(class_or_instance)
351
360
352
361
Returns a tuple of :class: `Field ` objects that define the fields for this
@@ -595,8 +604,8 @@ Init-only variables
595
604
596
605
Another place where :func: `@dataclass <dataclass> ` inspects a type annotation is to
597
606
determine if a field is an init-only variable. It does this by seeing
598
- if the type of a field is of type `` dataclasses. InitVar` `. If a field
599
- is an `` InitVar ` `, it is considered a pseudo-field called an init-only
607
+ if the type of a field is of type :class: ` InitVar `. If a field
608
+ is an :class: ` InitVar `, it is considered a pseudo-field called an init-only
600
609
field. As it is not a true field, it is not returned by the
601
610
module-level :func: `fields ` function. Init-only fields are added as
602
611
parameters to the generated :meth: `~object.__init__ ` method, and are passed to
You can’t perform that action at this time.
0 commit comments