Skip to content

Commit fd5b488

Browse files
committed
Selectivly add some additional xrefs to dunders in contextlib docs
1 parent a203698 commit fd5b488

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Doc/library/contextlib.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ Functions and classes provided:
228228

229229
.. function:: nullcontext(enter_result=None)
230230

231-
Return a context manager that returns *enter_result* from ``__enter__``, but
231+
Return a context manager that returns *enter_result* from :meth:`~object.__enter__`, but
232232
otherwise does nothing. It is intended to be used as a stand-in for an
233233
optional context manager, for example::
234234

@@ -335,7 +335,7 @@ Functions and classes provided:
335335
For example, the output of :func:`help` normally is sent to *sys.stdout*.
336336
You can capture that output in a string by redirecting the output to an
337337
:class:`io.StringIO` object. The replacement stream is returned from the
338-
``__enter__`` method and so is available as the target of the
338+
:meth:`~object.__enter__` method and so is available as the target of the
339339
:keyword:`with` statement::
340340

341341
with redirect_stdout(io.StringIO()) as f:
@@ -396,7 +396,8 @@ Functions and classes provided:
396396
A base class that enables a context manager to also be used as a decorator.
397397

398398
Context managers inheriting from ``ContextDecorator`` have to implement
399-
``__enter__`` and ``__exit__`` as normal. ``__exit__`` retains its optional
399+
:meth:`~object.__enter__` and :meth:`~object.__exit__` as normal.
400+
``__exit__`` retains its optional
400401
exception handling even when used as a decorator.
401402

402403
``ContextDecorator`` is used by :func:`contextmanager`, so you get this
@@ -710,9 +711,9 @@ context management protocol.
710711
Catching exceptions from ``__enter__`` methods
711712
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
712713

713-
It is occasionally desirable to catch exceptions from an ``__enter__``
714+
It is occasionally desirable to catch exceptions from an :meth:`~object.__enter__`
714715
method implementation, *without* inadvertently catching exceptions from
715-
the :keyword:`with` statement body or the context manager's ``__exit__``
716+
the :keyword:`with` statement body or the context manager's :meth:`~object.__exit__`
716717
method. By using :class:`ExitStack` the steps in the context management
717718
protocol can be separated slightly in order to allow this::
718719

0 commit comments

Comments
 (0)