Skip to content

Commit

Permalink
bpo-46290: Fix parameter names in dataclasses docs (GH-30450)
Browse files Browse the repository at this point in the history
(cherry picked from commit ef5376e)

Co-authored-by: Zsolt Dollenstein <zsol.zsol@gmail.com>
  • Loading branch information
miss-islington and zsol committed Jan 8, 2022
1 parent 566d70a commit cd95033
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions Doc/library/dataclasses.rst
Expand Up @@ -287,9 +287,9 @@ Module-level decorators, classes, and functions
Raises :exc:`TypeError` if not passed a dataclass or instance of one.
Does not return pseudo-fields which are ``ClassVar`` or ``InitVar``.

.. function:: asdict(instance, *, dict_factory=dict)
.. function:: asdict(obj, *, dict_factory=dict)

Converts the dataclass ``instance`` to a dict (by using the
Converts the dataclass ``obj`` to a dict (by using the
factory function ``dict_factory``). Each dataclass is converted
to a dict of its fields, as ``name: value`` pairs. dataclasses, dicts,
lists, and tuples are recursed into. Other objects are copied with
Expand All @@ -314,14 +314,14 @@ Module-level decorators, classes, and functions

To create a shallow copy, the following workaround may be used::

dict((field.name, getattr(instance, field.name)) for field in fields(instance))
dict((field.name, getattr(obj, field.name)) for field in fields(obj))

:func:`asdict` raises :exc:`TypeError` if ``instance`` is not a dataclass
:func:`asdict` raises :exc:`TypeError` if ``obj`` is not a dataclass
instance.

.. function:: astuple(instance, *, tuple_factory=tuple)
.. function:: astuple(obj, *, tuple_factory=tuple)

Converts the dataclass ``instance`` to a tuple (by using the
Converts the dataclass ``obj`` to a tuple (by using the
factory function ``tuple_factory``). Each dataclass is converted
to a tuple of its field values. dataclasses, dicts, lists, and
tuples are recursed into. Other objects are copied with
Expand All @@ -334,9 +334,9 @@ Module-level decorators, classes, and functions

To create a shallow copy, the following workaround may be used::

tuple(getattr(instance, field.name) for field in dataclasses.fields(instance))
tuple(getattr(obj, field.name) for field in dataclasses.fields(obj))

:func:`astuple` raises :exc:`TypeError` if ``instance`` is not a dataclass
:func:`astuple` raises :exc:`TypeError` if ``obj`` is not a dataclass
instance.

.. function:: make_dataclass(cls_name, fields, *, bases=(), namespace=None, init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False)
Expand Down Expand Up @@ -373,10 +373,10 @@ Module-level decorators, classes, and functions
def add_one(self):
return self.x + 1

.. function:: replace(instance, /, **changes)
.. function:: replace(obj, /, **changes)

Creates a new object of the same type as ``instance``, replacing
fields with values from ``changes``. If ``instance`` is not a Data
Creates a new object of the same type as ``obj``, replacing
fields with values from ``changes``. If ``obj`` is not a Data
Class, raises :exc:`TypeError`. If values in ``changes`` do not
specify fields, raises :exc:`TypeError`.

Expand All @@ -401,7 +401,7 @@ Module-level decorators, classes, and functions
``replace()`` (or similarly named) method which handles instance
copying.

.. function:: is_dataclass(class_or_instance)
.. function:: is_dataclass(obj)

Return ``True`` if its parameter is a dataclass or an instance of one,
otherwise return ``False``.
Expand Down

0 comments on commit cd95033

Please sign in to comment.