@@ -81,7 +81,7 @@ Module contents
81
81
82
82
@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)
83
83
class C:
84
- ...
84
+ ...
85
85
86
86
The parameters to :func: `dataclass ` are:
87
87
@@ -482,10 +482,10 @@ Module contents
482
482
483
483
@dataclass
484
484
class Point:
485
- x: float
486
- _: KW_ONLY
487
- y: float
488
- z: float
485
+ x: float
486
+ _: KW_ONLY
487
+ y: float
488
+ z: float
489
489
490
490
p = Point(0, y=1.5, z=2.0)
491
491
@@ -773,24 +773,24 @@ default value have the following special behaviors:
773
773
::
774
774
775
775
class IntConversionDescriptor:
776
- def __init__(self, *, default):
777
- self._default = default
776
+ def __init__(self, *, default):
777
+ self._default = default
778
778
779
- def __set_name__(self, owner, name):
780
- self._name = "_" + name
779
+ def __set_name__(self, owner, name):
780
+ self._name = "_" + name
781
781
782
- def __get__(self, obj, type):
783
- if obj is None:
784
- return self._default
782
+ def __get__(self, obj, type):
783
+ if obj is None:
784
+ return self._default
785
785
786
- return getattr(obj, self._name, self._default)
786
+ return getattr(obj, self._name, self._default)
787
787
788
- def __set__(self, obj, value):
789
- setattr(obj, self._name, int(value))
788
+ def __set__(self, obj, value):
789
+ setattr(obj, self._name, int(value))
790
790
791
791
@dataclass
792
792
class InventoryItem:
793
- quantity_on_hand: IntConversionDescriptor = IntConversionDescriptor(default=100)
793
+ quantity_on_hand: IntConversionDescriptor = IntConversionDescriptor(default=100)
794
794
795
795
i = InventoryItem()
796
796
print(i.quantity_on_hand) # 100
0 commit comments