summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorRoman Novak <44512421+romanngg@users.noreply.github.com>2022-07-26 14:48:58 (GMT)
committerGitHub <noreply@github.com>2022-07-26 14:48:58 (GMT)
commitb8c528694edb7a31020116956cc4daf07a5cd97f (patch)
tree3cd3f77b930df9afb70b72127069e83a235b807b /Lib
parent75c0c1b99312877bdd5b3583616f737d32869bac (diff)
downloadcpython-b8c528694edb7a31020116956cc4daf07a5cd97f.zip
cpython-b8c528694edb7a31020116956cc4daf07a5cd97f.tar.gz
cpython-b8c528694edb7a31020116956cc4daf07a5cd97f.tar.bz2
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.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/dataclasses.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/Lib/dataclasses.py b/Lib/dataclasses.py
index 103ecba..a567a33 100644
--- a/Lib/dataclasses.py
+++ b/Lib/dataclasses.py
@@ -1255,7 +1255,7 @@ def asdict(obj, *, dict_factory=dict):
"""Return the fields of a dataclass instance as a new dictionary mapping
field names to field values.
- Example usage:
+ Example usage::
@dataclass
class C:
@@ -1326,8 +1326,8 @@ def astuple(obj, *, tuple_factory=tuple):
x: int
y: int
- c = C(1, 2)
- assert astuple(c) == (1, 2)
+ c = C(1, 2)
+ assert astuple(c) == (1, 2)
If given, 'tuple_factory' will be used instead of built-in tuple.
The function applies recursively to field values that are
@@ -1376,11 +1376,11 @@ def make_dataclass(cls_name, fields, *, bases=(), namespace=None, init=True,
The dataclass name will be 'cls_name'. 'fields' is an iterable
of either (name), (name, type) or (name, type, Field) objects. If type is
omitted, use the string 'typing.Any'. Field objects are created by
- the equivalent of calling 'field(name, type [, Field-info])'.
+ the equivalent of calling 'field(name, type [, Field-info])'.::
C = make_dataclass('C', ['x', ('y', int), ('z', int, field(init=False))], bases=(Base,))
- is equivalent to:
+ is equivalent to::
@dataclass
class C(Base):
@@ -1444,7 +1444,7 @@ def make_dataclass(cls_name, fields, *, bases=(), namespace=None, init=True,
def replace(obj, /, **changes):
"""Return a new object replacing specified fields with new values.
- This is especially useful for frozen classes. Example usage:
+ This is especially useful for frozen classes. Example usage::
@dataclass(frozen=True)
class C:
@@ -1454,7 +1454,7 @@ def replace(obj, /, **changes):
c = C(1, 2)
c1 = replace(c, x=3)
assert c1.x == 3 and c1.y == 2
- """
+ """
# We're going to mutate 'changes', but that's okay because it's a
# new dict, even if called with 'replace(obj, **my_changes)'.