Skip to content

Commit b8c5286

Browse files
authored
Fix minor docstring issues in dataclasses.py. (gh-93024)
Previously, when using `functools.wrap` around them (and inherit their docstrings), sphinx renders the docstrings badly and raises warnings about wrong indent.
1 parent 75c0c1b commit b8c5286

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Lib/dataclasses.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1255,7 +1255,7 @@ def asdict(obj, *, dict_factory=dict):
12551255
"""Return the fields of a dataclass instance as a new dictionary mapping
12561256
field names to field values.
12571257
1258-
Example usage:
1258+
Example usage::
12591259
12601260
@dataclass
12611261
class C:
@@ -1326,8 +1326,8 @@ class C:
13261326
x: int
13271327
y: int
13281328
1329-
c = C(1, 2)
1330-
assert astuple(c) == (1, 2)
1329+
c = C(1, 2)
1330+
assert astuple(c) == (1, 2)
13311331
13321332
If given, 'tuple_factory' will be used instead of built-in tuple.
13331333
The function applies recursively to field values that are
@@ -1376,11 +1376,11 @@ def make_dataclass(cls_name, fields, *, bases=(), namespace=None, init=True,
13761376
The dataclass name will be 'cls_name'. 'fields' is an iterable
13771377
of either (name), (name, type) or (name, type, Field) objects. If type is
13781378
omitted, use the string 'typing.Any'. Field objects are created by
1379-
the equivalent of calling 'field(name, type [, Field-info])'.
1379+
the equivalent of calling 'field(name, type [, Field-info])'.::
13801380
13811381
C = make_dataclass('C', ['x', ('y', int), ('z', int, field(init=False))], bases=(Base,))
13821382
1383-
is equivalent to:
1383+
is equivalent to::
13841384
13851385
@dataclass
13861386
class C(Base):
@@ -1444,7 +1444,7 @@ def exec_body_callback(ns):
14441444
def replace(obj, /, **changes):
14451445
"""Return a new object replacing specified fields with new values.
14461446
1447-
This is especially useful for frozen classes. Example usage:
1447+
This is especially useful for frozen classes. Example usage::
14481448
14491449
@dataclass(frozen=True)
14501450
class C:
@@ -1454,7 +1454,7 @@ class C:
14541454
c = C(1, 2)
14551455
c1 = replace(c, x=3)
14561456
assert c1.x == 3 and c1.y == 2
1457-
"""
1457+
"""
14581458

14591459
# We're going to mutate 'changes', but that's okay because it's a
14601460
# new dict, even if called with 'replace(obj, **my_changes)'.

0 commit comments

Comments
 (0)