Skip to content

Commit 3c19c88

Browse files
[3.14] Hide "object" prefix on dunders in contextlib docs & selectivly link some more (GH-145436) (#145443)
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
1 parent 26a0dba commit 3c19c88

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

Doc/library/contextlib.rst

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ Functions and classes provided:
2121
.. class:: AbstractContextManager
2222

2323
An :term:`abstract base class` for classes that implement
24-
:meth:`object.__enter__` and :meth:`object.__exit__`. A default
25-
implementation for :meth:`object.__enter__` is provided which returns
26-
``self`` while :meth:`object.__exit__` is an abstract method which by default
24+
:meth:`~object.__enter__` and :meth:`~object.__exit__`. A default
25+
implementation for :meth:`~object.__enter__` is provided which returns
26+
``self`` while :meth:`~object.__exit__` is an abstract method which by default
2727
returns ``None``. See also the definition of :ref:`typecontextmanager`.
2828

2929
.. versionadded:: 3.6
@@ -32,9 +32,9 @@ Functions and classes provided:
3232
.. class:: AbstractAsyncContextManager
3333

3434
An :term:`abstract base class` for classes that implement
35-
:meth:`object.__aenter__` and :meth:`object.__aexit__`. A default
36-
implementation for :meth:`object.__aenter__` is provided which returns
37-
``self`` while :meth:`object.__aexit__` is an abstract method which by default
35+
:meth:`~object.__aenter__` and :meth:`~object.__aexit__`. A default
36+
implementation for :meth:`~object.__aenter__` is provided which returns
37+
``self`` while :meth:`~object.__aexit__` is an abstract method which by default
3838
returns ``None``. See also the definition of
3939
:ref:`async-context-managers`.
4040

@@ -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
@@ -697,9 +698,9 @@ context management protocol.
697698
Catching exceptions from ``__enter__`` methods
698699
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
699700

700-
It is occasionally desirable to catch exceptions from an ``__enter__``
701+
It is occasionally desirable to catch exceptions from an :meth:`~object.__enter__`
701702
method implementation, *without* inadvertently catching exceptions from
702-
the :keyword:`with` statement body or the context manager's ``__exit__``
703+
the :keyword:`with` statement body or the context manager's :meth:`~object.__exit__`
703704
method. By using :class:`ExitStack` the steps in the context management
704705
protocol can be separated slightly in order to allow this::
705706

0 commit comments

Comments
 (0)