[Python-checkins] Fix minor docstring issues in `dataclasses.py`. (gh-93024) (GH-95286)

ambv webhook-mailer at python.org
Wed Jul 27 04:08:30 EDT 2022


https://github.com/python/cpython/commit/f083adfdacfa90f90e1c1d8cb5ed0cb087f585c0
commit: f083adfdacfa90f90e1c1d8cb5ed0cb087f585c0
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: ambv <lukasz at langa.pl>
date: 2022年07月27日T10:08:21+02:00
summary:
Fix minor docstring issues in `dataclasses.py`. (gh-93024) (GH-95286)
Previously, when using `functools.wrap` around them (and inherit their docstrings), sphinx renders the docstrings badly and raises warnings about wrong indent.
(cherry picked from commit b8c528694edb7a31020116956cc4daf07a5cd97f)
Co-authored-by: Roman Novak <44512421+romanngg at users.noreply.github.com>
files:
M Lib/dataclasses.py
diff --git a/Lib/dataclasses.py b/Lib/dataclasses.py
index 103ecbafb2e27..a567a33d646f4 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 @@ class C:
 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 exec_body_callback(ns):
 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 @@ class C:
 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)'.


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /