Skip to content

Commit d036db7

Browse files
gh-106892: Use roles :data: and :const: for referencing module variables (GH-106894)
1 parent 8d397ee commit d036db7

40 files changed

+111
-111
lines changed

Doc/c-api/import.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ Importing Modules
142142
read from a Python bytecode file or obtained from the built-in function
143143
:func:`compile`, load the module. Return a new reference to the module object,
144144
or ``NULL`` with an exception set if an error occurred. *name*
145-
is removed from :attr:`sys.modules` in error cases, even if *name* was already
146-
in :attr:`sys.modules` on entry to :c:func:`PyImport_ExecCodeModule`. Leaving
147-
incompletely initialized modules in :attr:`sys.modules` is dangerous, as imports of
145+
is removed from :data:`sys.modules` in error cases, even if *name* was already
146+
in :data:`sys.modules` on entry to :c:func:`PyImport_ExecCodeModule`. Leaving
147+
incompletely initialized modules in :data:`sys.modules` is dangerous, as imports of
148148
such modules have no way to know that the module object is an unknown (and
149149
probably damaged with respect to the module author's intents) state.
150150

Doc/library/__main__.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -336,12 +336,12 @@ Note that importing ``__main__`` doesn't cause any issues with unintentionally
336336
running top-level code meant for script use which is put in the
337337
``if __name__ == "__main__"`` block of the ``start`` module. Why does this work?
338338

339-
Python inserts an empty ``__main__`` module in :attr:`sys.modules` at
339+
Python inserts an empty ``__main__`` module in :data:`sys.modules` at
340340
interpreter startup, and populates it by running top-level code. In our example
341341
this is the ``start`` module which runs line by line and imports ``namely``.
342342
In turn, ``namely`` imports ``__main__`` (which is really ``start``). That's an
343343
import cycle! Fortunately, since the partially populated ``__main__``
344-
module is present in :attr:`sys.modules`, Python passes that to ``namely``.
344+
module is present in :data:`sys.modules`, Python passes that to ``namely``.
345345
See :ref:`Special considerations for __main__ <import-dunder-main>` in the
346346
import system's reference for details on how this works.
347347

Doc/library/asyncio-subprocess.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Creating Subprocesses
6868

6969
The *limit* argument sets the buffer limit for :class:`StreamReader`
7070
wrappers for :attr:`Process.stdout` and :attr:`Process.stderr`
71-
(if :attr:`subprocess.PIPE` is passed to *stdout* and *stderr* arguments).
71+
(if :const:`subprocess.PIPE` is passed to *stdout* and *stderr* arguments).
7272

7373
Return a :class:`~asyncio.subprocess.Process` instance.
7474

@@ -86,7 +86,7 @@ Creating Subprocesses
8686

8787
The *limit* argument sets the buffer limit for :class:`StreamReader`
8888
wrappers for :attr:`Process.stdout` and :attr:`Process.stderr`
89-
(if :attr:`subprocess.PIPE` is passed to *stdout* and *stderr* arguments).
89+
(if :const:`subprocess.PIPE` is passed to *stdout* and *stderr* arguments).
9090

9191
Return a :class:`~asyncio.subprocess.Process` instance.
9292

Doc/library/compileall.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ There is no command-line option to control the optimization level used by the
141141
:func:`compile` function, because the Python interpreter itself already
142142
provides the option: :program:`python -O -m compileall`.
143143

144-
Similarly, the :func:`compile` function respects the :attr:`sys.pycache_prefix`
144+
Similarly, the :func:`compile` function respects the :data:`sys.pycache_prefix`
145145
setting. The generated bytecode cache will only be useful if :func:`compile` is
146-
run with the same :attr:`sys.pycache_prefix` (if any) that will be used at
146+
run with the same :data:`sys.pycache_prefix` (if any) that will be used at
147147
runtime.
148148

149149
Public functions

Doc/library/devmode.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Effects of the Python Development Mode:
8181
ignored for empty strings.
8282

8383
* The :class:`io.IOBase` destructor logs ``close()`` exceptions.
84-
* Set the :attr:`~sys.flags.dev_mode` attribute of :attr:`sys.flags` to
84+
* Set the :attr:`~sys.flags.dev_mode` attribute of :data:`sys.flags` to
8585
``True``.
8686

8787
The Python Development Mode does not enable the :mod:`tracemalloc` module by

Doc/library/filecmp.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ The :class:`dircmp` class
7474

7575
Construct a new directory comparison object, to compare the directories *a*
7676
and *b*. *ignore* is a list of names to ignore, and defaults to
77-
:attr:`filecmp.DEFAULT_IGNORES`. *hide* is a list of names to hide, and
77+
:const:`filecmp.DEFAULT_IGNORES`. *hide* is a list of names to hide, and
7878
defaults to ``[os.curdir, os.pardir]``.
7979

8080
The :class:`dircmp` class compares files by doing *shallow* comparisons

Doc/library/ftplib.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ FTP_TLS Objects
431431

432432
.. attribute:: FTP_TLS.ssl_version
433433

434-
The SSL version to use (defaults to :attr:`ssl.PROTOCOL_SSLv23`).
434+
The SSL version to use (defaults to :data:`ssl.PROTOCOL_SSLv23`).
435435

436436
.. method:: FTP_TLS.auth()
437437

Doc/library/functions.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,7 @@ are always available. They are listed here in alphabetical order.
12311231

12321232
* Binary files are buffered in fixed-size chunks; the size of the buffer is
12331233
chosen using a heuristic trying to determine the underlying device's "block
1234-
size" and falling back on :attr:`io.DEFAULT_BUFFER_SIZE`. On many systems,
1234+
size" and falling back on :const:`io.DEFAULT_BUFFER_SIZE`. On many systems,
12351235
the buffer will typically be 4096 or 8192 bytes long.
12361236

12371237
* "Interactive" text files (files for which :meth:`~io.IOBase.isatty`

Doc/library/gc.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ values but should not rebind them):
260260

261261
.. versionchanged:: 3.4
262262
Following :pep:`442`, objects with a :meth:`~object.__del__` method don't end
263-
up in :attr:`gc.garbage` anymore.
263+
up in :data:`gc.garbage` anymore.
264264

265265
.. data:: callbacks
266266

Doc/library/gzip.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ Command line options
268268

269269
.. cmdoption:: file
270270

271-
If *file* is not specified, read from :attr:`sys.stdin`.
271+
If *file* is not specified, read from :data:`sys.stdin`.
272272

273273
.. cmdoption:: --fast
274274

Doc/library/importlib.resources.abc.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
suitable for reading (same as :attr:`pathlib.Path.open`).
131131

132132
When opening as text, accepts encoding parameters such as those
133-
accepted by :attr:`io.TextIOWrapper`.
133+
accepted by :class:`io.TextIOWrapper`.
134134

135135
.. method:: read_bytes()
136136

Doc/library/importlib.rst

+9-9
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ ABC hierarchy::
372372
The list of locations where the package's submodules will be found.
373373
Most of the time this is a single directory.
374374
The import system passes this attribute to ``__import__()`` and to finders
375-
in the same way as :attr:`sys.path` but just for the package.
375+
in the same way as :data:`sys.path` but just for the package.
376376
It is not set on non-package modules so it can be used
377377
as an indicator that the module is a package.
378378

@@ -609,7 +609,7 @@ ABC hierarchy::
609609
automatically.
610610

611611
When writing to the path fails because the path is read-only
612-
(:attr:`errno.EACCES`/:exc:`PermissionError`), do not propagate the
612+
(:const:`errno.EACCES`/:exc:`PermissionError`), do not propagate the
613613
exception.
614614

615615
.. versionchanged:: 3.4
@@ -843,7 +843,7 @@ find and load modules.
843843

844844
.. classmethod:: path_hook(*loader_details)
845845

846-
A class method which returns a closure for use on :attr:`sys.path_hooks`.
846+
A class method which returns a closure for use on :data:`sys.path_hooks`.
847847
An instance of :class:`FileFinder` is returned by the closure using the
848848
path argument given to the closure directly and *loader_details*
849849
indirectly.
@@ -1184,10 +1184,10 @@ an :term:`importer`.
11841184
.. function:: find_spec(name, package=None)
11851185

11861186
Find the :term:`spec <module spec>` for a module, optionally relative to
1187-
the specified **package** name. If the module is in :attr:`sys.modules`,
1187+
the specified **package** name. If the module is in :data:`sys.modules`,
11881188
then ``sys.modules[name].__spec__`` is returned (unless the spec would be
11891189
``None`` or is not set, in which case :exc:`ValueError` is raised).
1190-
Otherwise a search using :attr:`sys.meta_path` is done. ``None`` is
1190+
Otherwise a search using :data:`sys.meta_path` is done. ``None`` is
11911191
returned if no spec is found.
11921192

11931193
If **name** is for a submodule (contains a dot), the parent module is
@@ -1259,7 +1259,7 @@ an :term:`importer`.
12591259
:meth:`~importlib.abc.Loader.create_module` method must return ``None`` or a
12601260
type for which its ``__class__`` attribute can be mutated along with not
12611261
using :term:`slots <__slots__>`. Finally, modules which substitute the object
1262-
placed into :attr:`sys.modules` will not work as there is no way to properly
1262+
placed into :data:`sys.modules` will not work as there is no way to properly
12631263
replace the module references throughout the interpreter safely;
12641264
:exc:`ValueError` is raised if such a substitution is detected.
12651265

@@ -1383,9 +1383,9 @@ For deep customizations of import, you typically want to implement an
13831383
:term:`importer`. This means managing both the :term:`finder` and :term:`loader`
13841384
side of things. For finders there are two flavours to choose from depending on
13851385
your needs: a :term:`meta path finder` or a :term:`path entry finder`. The
1386-
former is what you would put on :attr:`sys.meta_path` while the latter is what
1387-
you create using a :term:`path entry hook` on :attr:`sys.path_hooks` which works
1388-
with :attr:`sys.path` entries to potentially create a finder. This example will
1386+
former is what you would put on :data:`sys.meta_path` while the latter is what
1387+
you create using a :term:`path entry hook` on :data:`sys.path_hooks` which works
1388+
with :data:`sys.path` entries to potentially create a finder. This example will
13891389
show you how to register your own importers so that import will use them (for
13901390
creating an importer for yourself, read the documentation for the appropriate
13911391
classes defined within this package)::

Doc/library/json.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ The :mod:`json.tool` module provides a simple command line interface to validate
683683
and pretty-print JSON objects.
684684

685685
If the optional ``infile`` and ``outfile`` arguments are not
686-
specified, :attr:`sys.stdin` and :attr:`sys.stdout` will be used respectively:
686+
specified, :data:`sys.stdin` and :data:`sys.stdout` will be used respectively:
687687

688688
.. code-block:: shell-session
689689
@@ -721,12 +721,12 @@ Command line options
721721
}
722722
]
723723
724-
If *infile* is not specified, read from :attr:`sys.stdin`.
724+
If *infile* is not specified, read from :data:`sys.stdin`.
725725

726726
.. cmdoption:: outfile
727727

728728
Write the output of the *infile* to the given *outfile*. Otherwise, write it
729-
to :attr:`sys.stdout`.
729+
to :data:`sys.stdout`.
730730

731731
.. cmdoption:: --sort-keys
732732

Doc/library/logging.handlers.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -1051,8 +1051,8 @@ possible, while any potentially slow operations (such as sending an email via
10511051
occur (e.g. because a bounded queue has filled up), the
10521052
:meth:`~logging.Handler.handleError` method is called to handle the
10531053
error. This can result in the record silently being dropped (if
1054-
:attr:`logging.raiseExceptions` is ``False``) or a message printed to
1055-
``sys.stderr`` (if :attr:`logging.raiseExceptions` is ``True``).
1054+
:data:`logging.raiseExceptions` is ``False``) or a message printed to
1055+
``sys.stderr`` (if :data:`logging.raiseExceptions` is ``True``).
10561056

10571057
.. method:: prepare(record)
10581058

Doc/library/os.path.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ the :mod:`glob` module.)
410410
*start*. On Windows, :exc:`ValueError` is raised when *path* and *start*
411411
are on different drives.
412412

413-
*start* defaults to :attr:`os.curdir`.
413+
*start* defaults to :data:`os.curdir`.
414414

415415
.. availability:: Unix, Windows.
416416

Doc/library/os.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Notes on the availability of these functions:
6060
``'java'``.
6161

6262
.. seealso::
63-
:attr:`sys.platform` has a finer granularity. :func:`os.uname` gives
63+
:data:`sys.platform` has a finer granularity. :func:`os.uname` gives
6464
system-dependent version information.
6565

6666
The :mod:`platform` module provides detailed checks for the

Doc/library/platform.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Cross Platform
4646
universal files containing multiple architectures.
4747

4848
To get at the "64-bitness" of the current interpreter, it is more
49-
reliable to query the :attr:`sys.maxsize` attribute::
49+
reliable to query the :data:`sys.maxsize` attribute::
5050

5151
is_64bits = sys.maxsize > 2**32
5252

Doc/library/shutil.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ Directory and files operations
431431
determining if the file exists and executable.
432432

433433
When no *path* is specified, the results of :func:`os.environ` are used,
434-
returning either the "PATH" value or a fallback of :attr:`os.defpath`.
434+
returning either the "PATH" value or a fallback of :data:`os.defpath`.
435435

436436
On Windows, the current directory is prepended to the *path* if *mode* does
437437
not include ``os.X_OK``. When the *mode* does include ``os.X_OK``, the

Doc/library/stdtypes.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -5632,7 +5632,7 @@ From code, you can inspect the current limit and set a new one using these
56325632
a getter and setter for the interpreter-wide limit. Subinterpreters have
56335633
their own limit.
56345634

5635-
Information about the default and minimum can be found in :attr:`sys.int_info`:
5635+
Information about the default and minimum can be found in :data:`sys.int_info`:
56365636

56375637
* :data:`sys.int_info.default_max_str_digits <sys.int_info>` is the compiled-in
56385638
default limit.

Doc/library/subprocess.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -1610,15 +1610,15 @@ improves performance.
16101610

16111611
If you ever encounter a presumed highly unusual situation where you need to
16121612
prevent ``vfork()`` from being used by Python, you can set the
1613-
:attr:`subprocess._USE_VFORK` attribute to a false value.
1613+
:const:`subprocess._USE_VFORK` attribute to a false value.
16141614

16151615
::
16161616

16171617
subprocess._USE_VFORK = False # See CPython issue gh-NNNNNN.
16181618

16191619
Setting this has no impact on use of ``posix_spawn()`` which could use
16201620
``vfork()`` internally within its libc implementation. There is a similar
1621-
:attr:`subprocess._USE_POSIX_SPAWN` attribute if you need to prevent use of
1621+
:const:`subprocess._USE_POSIX_SPAWN` attribute if you need to prevent use of
16221622
that.
16231623

16241624
::

Doc/library/sys.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ always available.
166166
Python interpreter. (This information is not available in any other way ---
167167
``modules.keys()`` only lists the imported modules.)
168168

169-
See also the :attr:`sys.stdlib_module_names` list.
169+
See also the :data:`sys.stdlib_module_names` list.
170170

171171

172172
.. function:: call_tracing(func, args)
@@ -1287,20 +1287,20 @@ always available.
12871287
================ ===========================
12881288

12891289
.. versionchanged:: 3.3
1290-
On Linux, :attr:`sys.platform` doesn't contain the major version anymore.
1290+
On Linux, :data:`sys.platform` doesn't contain the major version anymore.
12911291
It is always ``'linux'``, instead of ``'linux2'`` or ``'linux3'``. Since
12921292
older Python versions include the version number, it is recommended to
12931293
always use the ``startswith`` idiom presented above.
12941294

12951295
.. versionchanged:: 3.8
1296-
On AIX, :attr:`sys.platform` doesn't contain the major version anymore.
1296+
On AIX, :data:`sys.platform` doesn't contain the major version anymore.
12971297
It is always ``'aix'``, instead of ``'aix5'`` or ``'aix7'``. Since
12981298
older Python versions include the version number, it is recommended to
12991299
always use the ``startswith`` idiom presented above.
13001300

13011301
.. seealso::
13021302

1303-
:attr:`os.name` has a coarser granularity. :func:`os.uname` gives
1303+
:data:`os.name` has a coarser granularity. :func:`os.uname` gives
13041304
system-dependent version information.
13051305

13061306
The :mod:`platform` module provides detailed checks for the
@@ -1743,7 +1743,7 @@ always available.
17431743
``email.mime`` sub-package and the ``email.message`` sub-module are not
17441744
listed.
17451745

1746-
See also the :attr:`sys.builtin_module_names` list.
1746+
See also the :data:`sys.builtin_module_names` list.
17471747

17481748
.. versionadded:: 3.10
17491749

Doc/library/tarfile.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ reused in custom filters:
938938

939939
Implements the ``'tar'`` filter.
940940

941-
- Strip leading slashes (``/`` and :attr:`os.sep`) from filenames.
941+
- Strip leading slashes (``/`` and :data:`os.sep`) from filenames.
942942
- :ref:`Refuse <tarfile-extraction-refuse>` to extract files with absolute
943943
paths (in case the name is absolute
944944
even after stripping slashes, e.g. ``C:/foo`` on Windows).
@@ -947,7 +947,7 @@ reused in custom filters:
947947
path (after following symlinks) would end up outside the destination.
948948
This raises :class:`~tarfile.OutsideDestinationError`.
949949
- Clear high mode bits (setuid, setgid, sticky) and group/other write bits
950-
(:attr:`~stat.S_IWGRP`|:attr:`~stat.S_IWOTH`).
950+
(:const:`~stat.S_IWGRP`|:const:`~stat.S_IWOTH`).
951951

952952
Return the modified ``TarInfo`` member.
953953

@@ -972,10 +972,10 @@ reused in custom filters:
972972
- For regular files, including hard links:
973973

974974
- Set the owner read and write permissions
975-
(:attr:`~stat.S_IRUSR`|:attr:`~stat.S_IWUSR`).
975+
(:const:`~stat.S_IRUSR`|:const:`~stat.S_IWUSR`).
976976
- Remove the group & other executable permission
977-
(:attr:`~stat.S_IXGRP`|:attr:`~stat.S_IXOTH`)
978-
if the owner doesn’t have it (:attr:`~stat.S_IXUSR`).
977+
(:const:`~stat.S_IXGRP`|:const:`~stat.S_IXOTH`)
978+
if the owner doesn’t have it (:const:`~stat.S_IXUSR`).
979979

980980
- For other files (directories), set ``mode`` to ``None``, so
981981
that extraction methods skip applying permission bits.

Doc/library/test.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ The :mod:`test.support` module defines the following classes:
10401040
`SetErrorMode <https://msdn.microsoft.com/en-us/library/windows/desktop/ms680621.aspx>`_.
10411041

10421042
On UNIX, :func:`resource.setrlimit` is used to set
1043-
:attr:`resource.RLIMIT_CORE`'s soft limit to 0 to prevent coredump file
1043+
:const:`resource.RLIMIT_CORE`'s soft limit to 0 to prevent coredump file
10441044
creation.
10451045

10461046
On both platforms, the old value is restored by :meth:`__exit__`.

Doc/library/tkinter.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ the modern themed widget set and API::
163163
interpreter and calls :func:`exec` on the contents of
164164
:file:`.{className}.py` and :file:`.{baseName}.py`. The path for the
165165
profile files is the :envvar:`HOME` environment variable or, if that
166-
isn't defined, then :attr:`os.curdir`.
166+
isn't defined, then :data:`os.curdir`.
167167

168168
.. attribute:: tk
169169

Doc/library/unittest.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,7 @@ Test cases
11341134

11351135
If given, *level* should be either a numeric logging level or
11361136
its string equivalent (for example either ``"ERROR"`` or
1137-
:attr:`logging.ERROR`). The default is :attr:`logging.INFO`.
1137+
:const:`logging.ERROR`). The default is :const:`logging.INFO`.
11381138

11391139
The test passes if at least one message emitted inside the ``with``
11401140
block matches the *logger* and *level* conditions, otherwise it fails.
@@ -1175,7 +1175,7 @@ Test cases
11751175

11761176
If given, *level* should be either a numeric logging level or
11771177
its string equivalent (for example either ``"ERROR"`` or
1178-
:attr:`logging.ERROR`). The default is :attr:`logging.INFO`.
1178+
:const:`logging.ERROR`). The default is :const:`logging.INFO`.
11791179

11801180
Unlike :meth:`assertLogs`, nothing will be returned by the context
11811181
manager.

0 commit comments

Comments
 (0)