Skip to content

dataclasses docs: consistent indentation (4 spaces) in examples #98855

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions Doc/library/dataclasses.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down