Skip to content

Commit 60edc70

Browse files
miss-islingtonerlend-aaslandAA-TurnerYhg1s
authored
[3.12] Docs: Fix Sphinx warnings in io.rst (GH-107903) (#108093)
Docs: Fix Sphinx warnings in io.rst (GH-107903) - Mark up parameter and argument names properly - If possible, link to docs for methods like `seek`, `tell`, `write`, `read`, etc. (cherry picked from commit 5c76899) Co-authored-by: Erlend E. Aasland <[email protected]> Co-authored-by: Adam Turner <[email protected]> Co-authored-by: T. Wouters <[email protected]>
1 parent 9342ac3 commit 60edc70

File tree

2 files changed

+36
-36
lines changed

2 files changed

+36
-36
lines changed

Doc/library/io.rst

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ location), or only sequential access (for example in the case of a socket or
3838
pipe).
3939

4040
All streams are careful about the type of data you give to them. For example
41-
giving a :class:`str` object to the ``write()`` method of a binary stream
41+
giving a :class:`str` object to the :meth:`!write` method of a binary stream
4242
will raise a :exc:`TypeError`. So will giving a :class:`bytes` object to the
43-
``write()`` method of a text stream.
43+
:meth:`!write` method of a text stream.
4444

4545
.. versionchanged:: 3.3
4646
Operations that used to raise :exc:`IOError` now raise :exc:`OSError`, since
@@ -146,7 +146,7 @@ Opt-in EncodingWarning
146146
See :pep:`597` for more details.
147147

148148
To find where the default locale encoding is used, you can enable
149-
the ``-X warn_default_encoding`` command line option or set the
149+
the :option:`-X warn_default_encoding <-X>` command line option or set the
150150
:envvar:`PYTHONWARNDEFAULTENCODING` environment variable, which will
151151
emit an :exc:`EncodingWarning` when the default encoding is used.
152152

@@ -175,7 +175,7 @@ High-level Module Interface
175175
.. audit-event:: open path,mode,flags io.open
176176

177177
This function raises an :ref:`auditing event <auditing>` ``open`` with
178-
arguments ``path``, ``mode`` and ``flags``. The ``mode`` and ``flags``
178+
arguments *path*, *mode* and *flags*. The *mode* and *flags*
179179
arguments may have been modified or inferred from the original call.
180180

181181

@@ -184,10 +184,10 @@ High-level Module Interface
184184
Opens the provided file with mode ``'rb'``. This function should be used
185185
when the intent is to treat the contents as executable code.
186186

187-
``path`` should be a :class:`str` and an absolute path.
187+
*path* should be a :class:`str` and an absolute path.
188188

189189
The behavior of this function may be overridden by an earlier call to the
190-
:c:func:`PyFile_SetOpenCodeHook`. However, assuming that ``path`` is a
190+
:c:func:`PyFile_SetOpenCodeHook`. However, assuming that *path* is a
191191
:class:`str` and an absolute path, ``open_code(path)`` should always behave
192192
the same as ``open(path, 'rb')``. Overriding the behavior is intended for
193193
additional validation or preprocessing of the file.
@@ -258,7 +258,7 @@ standard stream implementations.
258258
The abstract base classes also provide default implementations of some
259259
methods in order to help implementation of concrete stream classes. For
260260
example, :class:`BufferedIOBase` provides unoptimized implementations of
261-
:meth:`~IOBase.readinto` and :meth:`~IOBase.readline`.
261+
:meth:`!readinto` and :meth:`!readline`.
262262

263263
At the top of the I/O hierarchy is the abstract base class :class:`IOBase`. It
264264
defines the basic interface to a stream. Note, however, that there is no
@@ -320,8 +320,8 @@ I/O Base Classes
320320
implementations represent a file that cannot be read, written or
321321
seeked.
322322

323-
Even though :class:`IOBase` does not declare :meth:`read`
324-
or :meth:`write` because their signatures will vary, implementations and
323+
Even though :class:`IOBase` does not declare :meth:`!read`
324+
or :meth:`!write` because their signatures will vary, implementations and
325325
clients should consider those methods part of the interface. Also,
326326
implementations may raise a :exc:`ValueError` (or :exc:`UnsupportedOperation`)
327327
when operations they do not support are called.
@@ -379,8 +379,8 @@ I/O Base Classes
379379

380380
.. method:: readable()
381381

382-
Return ``True`` if the stream can be read from. If ``False``, :meth:`read`
383-
will raise :exc:`OSError`.
382+
Return ``True`` if the stream can be read from.
383+
If ``False``, :meth:`!read` will raise :exc:`OSError`.
384384

385385
.. method:: readline(size=-1, /)
386386

@@ -401,25 +401,25 @@ I/O Base Classes
401401
hint.
402402

403403
Note that it's already possible to iterate on file objects using ``for
404-
line in file: ...`` without calling ``file.readlines()``.
404+
line in file: ...`` without calling :meth:`!file.readlines`.
405405

406406
.. method:: seek(offset, whence=SEEK_SET, /)
407407

408408
Change the stream position to the given byte *offset*. *offset* is
409409
interpreted relative to the position indicated by *whence*. The default
410-
value for *whence* is :data:`SEEK_SET`. Values for *whence* are:
410+
value for *whence* is :data:`!SEEK_SET`. Values for *whence* are:
411411

412-
* :data:`SEEK_SET` or ``0`` -- start of the stream (the default);
412+
* :data:`!SEEK_SET` or ``0`` -- start of the stream (the default);
413413
*offset* should be zero or positive
414-
* :data:`SEEK_CUR` or ``1`` -- current stream position; *offset* may
414+
* :data:`!SEEK_CUR` or ``1`` -- current stream position; *offset* may
415415
be negative
416-
* :data:`SEEK_END` or ``2`` -- end of the stream; *offset* is usually
416+
* :data:`!SEEK_END` or ``2`` -- end of the stream; *offset* is usually
417417
negative
418418

419419
Return the new absolute position.
420420

421421
.. versionadded:: 3.1
422-
The ``SEEK_*`` constants.
422+
The :data:`!SEEK_*` constants.
423423

424424
.. versionadded:: 3.3
425425
Some operating systems could support additional values, like
@@ -450,7 +450,7 @@ I/O Base Classes
450450
.. method:: writable()
451451

452452
Return ``True`` if the stream supports writing. If ``False``,
453-
:meth:`write` and :meth:`truncate` will raise :exc:`OSError`.
453+
:meth:`!write` and :meth:`truncate` will raise :exc:`OSError`.
454454

455455
.. method:: writelines(lines, /)
456456

@@ -654,8 +654,9 @@ Raw File I/O
654654
implies writing, so this mode behaves in a similar way to ``'w'``. Add a
655655
``'+'`` to the mode to allow simultaneous reading and writing.
656656

657-
The :meth:`read` (when called with a positive argument), :meth:`readinto`
658-
and :meth:`write` methods on this class will only make one system call.
657+
The :meth:`~RawIOBase.read` (when called with a positive argument),
658+
:meth:`~RawIOBase.readinto` and :meth:`~RawIOBase.write` methods on this
659+
class will only make one system call.
659660

660661
A custom opener can be used by passing a callable as *opener*. The underlying
661662
file descriptor for the file object is then obtained by calling *opener* with
@@ -791,8 +792,8 @@ than raw I/O does.
791792
object under various conditions, including:
792793

793794
* when the buffer gets too small for all pending data;
794-
* when :meth:`flush()` is called;
795-
* when a :meth:`seek()` is requested (for :class:`BufferedRandom` objects);
795+
* when :meth:`flush` is called;
796+
* when a :meth:`~IOBase.seek` is requested (for :class:`BufferedRandom` objects);
796797
* when the :class:`BufferedWriter` object is closed or destroyed.
797798

798799
The constructor creates a :class:`BufferedWriter` for the given writeable
@@ -826,8 +827,8 @@ than raw I/O does.
826827
:data:`DEFAULT_BUFFER_SIZE`.
827828

828829
:class:`BufferedRandom` is capable of anything :class:`BufferedReader` or
829-
:class:`BufferedWriter` can do. In addition, :meth:`seek` and :meth:`tell`
830-
are guaranteed to be implemented.
830+
:class:`BufferedWriter` can do. In addition, :meth:`~IOBase.seek` and
831+
:meth:`~IOBase.tell` are guaranteed to be implemented.
831832

832833

833834
.. class:: BufferedRWPair(reader, writer, buffer_size=DEFAULT_BUFFER_SIZE, /)
@@ -904,7 +905,7 @@ Text I/O
904905

905906
.. method:: readline(size=-1, /)
906907

907-
Read until newline or EOF and return a single ``str``. If the stream is
908+
Read until newline or EOF and return a single :class:`str`. If the stream is
908909
already at EOF, an empty string is returned.
909910

910911
If *size* is specified, at most *size* characters will be read.
@@ -913,22 +914,22 @@ Text I/O
913914

914915
Change the stream position to the given *offset*. Behaviour depends on
915916
the *whence* parameter. The default value for *whence* is
916-
:data:`SEEK_SET`.
917+
:data:`!SEEK_SET`.
917918

918-
* :data:`SEEK_SET` or ``0``: seek from the start of the stream
919+
* :data:`!SEEK_SET` or ``0``: seek from the start of the stream
919920
(the default); *offset* must either be a number returned by
920921
:meth:`TextIOBase.tell`, or zero. Any other *offset* value
921922
produces undefined behaviour.
922-
* :data:`SEEK_CUR` or ``1``: "seek" to the current position;
923+
* :data:`!SEEK_CUR` or ``1``: "seek" to the current position;
923924
*offset* must be zero, which is a no-operation (all other values
924925
are unsupported).
925-
* :data:`SEEK_END` or ``2``: seek to the end of the stream;
926+
* :data:`!SEEK_END` or ``2``: seek to the end of the stream;
926927
*offset* must be zero (all other values are unsupported).
927928

928929
Return the new absolute position as an opaque number.
929930

930931
.. versionadded:: 3.1
931-
The ``SEEK_*`` constants.
932+
The :data:`!SEEK_*` constants.
932933

933934
.. method:: tell()
934935

@@ -988,10 +989,10 @@ Text I/O
988989
takes place. If *newline* is any of the other legal values, any ``'\n'``
989990
characters written are translated to the given string.
990991

991-
If *line_buffering* is ``True``, :meth:`flush` is implied when a call to
992+
If *line_buffering* is ``True``, :meth:`~IOBase.flush` is implied when a call to
992993
write contains a newline character or a carriage return.
993994

994-
If *write_through* is ``True``, calls to :meth:`write` are guaranteed
995+
If *write_through* is ``True``, calls to :meth:`~BufferedIOBase.write` are guaranteed
995996
not to be buffered: any data written on the :class:`TextIOWrapper`
996997
object is immediately handled to its underlying binary *buffer*.
997998

@@ -1070,7 +1071,7 @@ Text I/O
10701071

10711072
.. method:: getvalue()
10721073

1073-
Return a ``str`` containing the entire contents of the buffer.
1074+
Return a :class:`str` containing the entire contents of the buffer.
10741075
Newlines are decoded as if by :meth:`~TextIOBase.read`, although
10751076
the stream position is not changed.
10761077

@@ -1125,7 +1126,7 @@ Text I/O over a binary storage (such as a file) is significantly slower than
11251126
binary I/O over the same storage, because it requires conversions between
11261127
unicode and binary data using a character codec. This can become noticeable
11271128
handling huge amounts of text data like large log files. Also,
1128-
:meth:`TextIOWrapper.tell` and :meth:`TextIOWrapper.seek` are both quite slow
1129+
:meth:`~TextIOBase.tell` and :meth:`~TextIOBase.seek` are both quite slow
11291130
due to the reconstruction algorithm used.
11301131

11311132
:class:`StringIO`, however, is a native in-memory unicode container and will
@@ -1135,7 +1136,7 @@ Multi-threading
11351136
^^^^^^^^^^^^^^^
11361137

11371138
:class:`FileIO` objects are thread-safe to the extent that the operating system
1138-
calls (such as ``read(2)`` under Unix) they wrap are thread-safe too.
1139+
calls (such as :manpage:`read(2)` under Unix) they wrap are thread-safe too.
11391140

11401141
Binary buffered objects (instances of :class:`BufferedReader`,
11411142
:class:`BufferedWriter`, :class:`BufferedRandom` and :class:`BufferedRWPair`)

Doc/tools/.nitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ Doc/library/http.server.rst
100100
Doc/library/importlib.resources.rst
101101
Doc/library/importlib.rst
102102
Doc/library/inspect.rst
103-
Doc/library/io.rst
104103
Doc/library/locale.rst
105104
Doc/library/logging.config.rst
106105
Doc/library/logging.handlers.rst

0 commit comments

Comments
 (0)