Skip to content

Commit ebcf757

Browse files
AlexWaygoodhugovk
andauthored
[3.12] gh-101100: Fix Sphinx nitpicks in library/tempfile.rst (#112886) (#112910)
(cherry-picked from commit 54410e6) Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
1 parent 6537151 commit ebcf757

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

Doc/library/tempfile.rst

+29-23
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This module creates temporary files and directories. It works on all
1818
supported platforms. :class:`TemporaryFile`, :class:`NamedTemporaryFile`,
1919
:class:`TemporaryDirectory`, and :class:`SpooledTemporaryFile` are high-level
2020
interfaces which provide automatic cleanup and can be used as
21-
context managers. :func:`mkstemp` and
21+
:term:`context managers <context manager>`. :func:`mkstemp` and
2222
:func:`mkdtemp` are lower-level functions which require manual cleanup.
2323

2424
All the user-callable functions and constructors take additional arguments which
@@ -41,7 +41,7 @@ The module defines the following user-callable items:
4141
this; your code should not rely on a temporary file created using this
4242
function having or not having a visible name in the file system.
4343

44-
The resulting object can be used as a context manager (see
44+
The resulting object can be used as a :term:`context manager` (see
4545
:ref:`tempfile-examples`). On completion of the context or
4646
destruction of the file object the temporary file will be removed
4747
from the filesystem.
@@ -87,9 +87,9 @@ The module defines the following user-callable items:
8787
determine whether and how the named file should be automatically deleted.
8888

8989
The returned object is always a :term:`file-like object` whose :attr:`!file`
90-
attribute is the underlying true file object. This :term:`file-like object`
90+
attribute is the underlying true file object. This file-like object
9191
can be used in a :keyword:`with` statement, just like a normal file. The
92-
name of the temporary file can be retrieved from the :attr:`name` attribute
92+
name of the temporary file can be retrieved from the :attr:`!name` attribute
9393
of the returned file-like object. On Unix, unlike with the
9494
:func:`TemporaryFile`, the directory entry does not get unlinked immediately
9595
after the file creation.
@@ -151,18 +151,20 @@ The module defines the following user-callable items:
151151
contents are written to disk and operation proceeds as with
152152
:func:`TemporaryFile`.
153153

154-
The resulting file has one additional method, :func:`rollover`, which
155-
causes the file to roll over to an on-disk file regardless of its size.
154+
.. method:: SpooledTemporaryFile.rollover
156155

157-
The returned object is a file-like object whose :attr:`_file` attribute
156+
The resulting file has one additional method, :meth:`!rollover`, which
157+
causes the file to roll over to an on-disk file regardless of its size.
158+
159+
The returned object is a file-like object whose :attr:`!_file` attribute
158160
is either an :class:`io.BytesIO` or :class:`io.TextIOWrapper` object
159161
(depending on whether binary or text *mode* was specified) or a true file
160-
object, depending on whether :func:`rollover` has been called. This
162+
object, depending on whether :meth:`rollover` has been called. This
161163
file-like object can be used in a :keyword:`with` statement, just like
162164
a normal file.
163165

164166
.. versionchanged:: 3.3
165-
the truncate method now accepts a ``size`` argument.
167+
the truncate method now accepts a *size* argument.
166168

167169
.. versionchanged:: 3.8
168170
Added *errors* parameter.
@@ -176,24 +178,28 @@ The module defines the following user-callable items:
176178
.. class:: TemporaryDirectory(suffix=None, prefix=None, dir=None, ignore_cleanup_errors=False, *, delete=True)
177179

178180
This class securely creates a temporary directory using the same rules as :func:`mkdtemp`.
179-
The resulting object can be used as a context manager (see
181+
The resulting object can be used as a :term:`context manager` (see
180182
:ref:`tempfile-examples`). On completion of the context or destruction
181183
of the temporary directory object, the newly created temporary directory
182184
and all its contents are removed from the filesystem.
183185

184-
The directory name can be retrieved from the :attr:`name` attribute of the
185-
returned object. When the returned object is used as a context manager, the
186-
:attr:`name` will be assigned to the target of the :keyword:`!as` clause in
187-
the :keyword:`with` statement, if there is one.
188-
189-
The directory can be explicitly cleaned up by calling the
190-
:func:`cleanup` method. If *ignore_cleanup_errors* is true, any unhandled
191-
exceptions during explicit or implicit cleanup (such as a
192-
:exc:`PermissionError` removing open files on Windows) will be ignored,
193-
and the remaining removable items deleted on a "best-effort" basis.
194-
Otherwise, errors will be raised in whatever context cleanup occurs
195-
(the :func:`cleanup` call, exiting the context manager, when the object
196-
is garbage-collected or during interpreter shutdown).
186+
.. attribute:: TemporaryDirectory.name
187+
188+
The directory name can be retrieved from the :attr:`!name` attribute of the
189+
returned object. When the returned object is used as a :term:`context manager`, the
190+
:attr:`!name` will be assigned to the target of the :keyword:`!as` clause in
191+
the :keyword:`with` statement, if there is one.
192+
193+
.. method:: TemporaryDirectory.cleanup
194+
195+
The directory can be explicitly cleaned up by calling the
196+
:meth:`!cleanup` method. If *ignore_cleanup_errors* is true, any unhandled
197+
exceptions during explicit or implicit cleanup (such as a
198+
:exc:`PermissionError` removing open files on Windows) will be ignored,
199+
and the remaining removable items deleted on a "best-effort" basis.
200+
Otherwise, errors will be raised in whatever context cleanup occurs
201+
(the :meth:`!cleanup` call, exiting the context manager, when the object
202+
is garbage-collected or during interpreter shutdown).
197203

198204
The *delete* parameter can be used to disable cleanup of the directory tree
199205
upon exiting the context. While it may seem unusual for a context manager

Doc/tools/.nitignore

-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ Doc/library/sunau.rst
107107
Doc/library/syslog.rst
108108
Doc/library/tarfile.rst
109109
Doc/library/telnetlib.rst
110-
Doc/library/tempfile.rst
111110
Doc/library/termios.rst
112111
Doc/library/test.rst
113112
Doc/library/tkinter.rst

0 commit comments

Comments
 (0)