]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
dataclasses docs: consistent indentation (4 spaces) in examples (#98855)
authorFC Stegerman <flx@obfusk.net>
Sat, 29 Oct 2022 17:06:52 +0000 (17:06 +0000)
committerGitHub <noreply@github.com>
Sat, 29 Oct 2022 17:06:52 +0000 (18:06 +0100)
Doc/library/dataclasses.rst

index ab8df8b02c5f7f2df89ba9e7f56f8ca10f938e7b..c4895aa822bf38ce42f255a2b23d45d5effa7bba 100644 (file)
@@ -81,7 +81,7 @@ Module contents
 
      @dataclass(init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False, match_args=True, kw_only=False, slots=False, weakref_slot=False)
      class C:
-        ...
+         ...
 
    The parameters to :func:`dataclass` are:
 
@@ -482,10 +482,10 @@ Module contents
 
     @dataclass
     class Point:
-      x: float
-      _: KW_ONLY
-      y: float
-      z: float
+        x: float
+        _: KW_ONLY
+        y: float
+        z: float
 
     p = Point(0, y=1.5, z=2.0)
 
@@ -773,24 +773,24 @@ default value have the following special behaviors:
 ::
 
   class IntConversionDescriptor:
-    def __init__(self, *, default):
-      self._default = default
+      def __init__(self, *, default):
+          self._default = default
 
-    def __set_name__(self, owner, name):
-      self._name = "_" + name
+      def __set_name__(self, owner, name):
+          self._name = "_" + name
 
-    def __get__(self, obj, type):
-      if obj is None:
-        return self._default
+      def __get__(self, obj, type):
+          if obj is None:
+              return self._default
 
-      return getattr(obj, self._name, self._default)
+          return getattr(obj, self._name, self._default)
 
-    def __set__(self, obj, value):
-      setattr(obj, self._name, int(value))
+      def __set__(self, obj, value):
+          setattr(obj, self._name, int(value))
 
   @dataclass
   class InventoryItem:
-    quantity_on_hand: IntConversionDescriptor = IntConversionDescriptor(default=100)
+      quantity_on_hand: IntConversionDescriptor = IntConversionDescriptor(default=100)
 
   i = InventoryItem()
   print(i.quantity_on_hand)   # 100