Skip to content

Commit

Permalink
Format None, True, False and NotImplemented as literals (pythonGH-118758
Browse files Browse the repository at this point in the history
)

(cherry picked from commit 05c2fe1)
  • Loading branch information
serhiy-storchaka committed May 8, 2024
1 parent b83b3cb commit 392bd67
Show file tree
Hide file tree
Showing 33 changed files with 76 additions and 75 deletions.
2 changes: 1 addition & 1 deletion Doc/c-api/object.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Object Protocol
Properly handle returning :c:data:`Py_NotImplemented` from within a C
function (that is, create a new :term:`strong reference`
to NotImplemented and return it).
to :const:`NotImplemented` and return it).


.. c:macro:: Py_PRINT_RAW
Expand Down
6 changes: 3 additions & 3 deletions Doc/library/_thread.rst
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,14 @@ Lock objects have the following methods:
time can acquire a lock --- that's their reason for existence).

If the *blocking* argument is present, the action depends on its
value: if it is False, the lock is only acquired if it can be acquired
immediately without waiting, while if it is True, the lock is acquired
value: if it is false, the lock is only acquired if it can be acquired
immediately without waiting, while if it is true, the lock is acquired
unconditionally as above.

If the floating-point *timeout* argument is present and positive, it
specifies the maximum wait time in seconds before returning. A negative
*timeout* argument specifies an unbounded wait. You cannot specify
a *timeout* if *blocking* is False.
a *timeout* if *blocking* is false.

The return value is ``True`` if the lock is acquired successfully,
``False`` if not.
Expand Down
2 changes: 1 addition & 1 deletion Doc/library/asyncio-task.rst
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ Running Tasks Concurrently
# [2, 6, 24]

.. note::
If *return_exceptions* is False, cancelling gather() after it
If *return_exceptions* is false, cancelling gather() after it
has been marked done won't cancel any submitted awaitables.
For instance, gather can be marked done after propagating an
exception to the caller, therefore, calling ``gather.cancel()``
Expand Down
22 changes: 11 additions & 11 deletions Doc/library/bdb.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ The :mod:`bdb` module also defines two classes:

.. attribute:: temporary

True if a :class:`Breakpoint` at (file, line) is temporary.
``True`` if a :class:`Breakpoint` at (file, line) is temporary.

.. attribute:: cond

Expand All @@ -99,7 +99,7 @@ The :mod:`bdb` module also defines two classes:

.. attribute:: enabled

True if :class:`Breakpoint` is enabled.
``True`` if :class:`Breakpoint` is enabled.

.. attribute:: bpbynumber

Expand Down Expand Up @@ -215,22 +215,22 @@ The :mod:`bdb` module also defines two classes:

.. method:: is_skipped_line(module_name)

Return True if *module_name* matches any skip pattern.
Return ``True`` if *module_name* matches any skip pattern.

.. method:: stop_here(frame)

Return True if *frame* is below the starting frame in the stack.
Return ``True`` if *frame* is below the starting frame in the stack.

.. method:: break_here(frame)

Return True if there is an effective breakpoint for this line.
Return ``True`` if there is an effective breakpoint for this line.

Check whether a line or function breakpoint exists and is in effect. Delete temporary
breakpoints based on information from :func:`effective`.

.. method:: break_anywhere(frame)

Return True if any breakpoint exists for *frame*'s filename.
Return ``True`` if any breakpoint exists for *frame*'s filename.

Derived classes should override these methods to gain control over debugger
operation.
Expand Down Expand Up @@ -344,7 +344,7 @@ The :mod:`bdb` module also defines two classes:

.. method:: get_break(filename, lineno)

Return True if there is a breakpoint for *lineno* in *filename*.
Return ``True`` if there is a breakpoint for *lineno* in *filename*.

.. method:: get_breaks(filename, lineno)

Expand Down Expand Up @@ -408,7 +408,7 @@ Finally, the module defines the following functions:

.. function:: checkfuncname(b, frame)

Return True if we should break here, depending on the way the
Return ``True`` if we should break here, depending on the way the
:class:`Breakpoint` *b* was set.

If it was set via line number, it checks if
Expand All @@ -427,14 +427,14 @@ Finally, the module defines the following functions:
:attr:`bplist <bdb.Breakpoint.bplist>` for the
(:attr:`file <bdb.Breakpoint.file>`, :attr:`line <bdb.Breakpoint.line>`)
(which must exist) that is :attr:`enabled <bdb.Breakpoint.enabled>`, for
which :func:`checkfuncname` is True, and that has neither a False
which :func:`checkfuncname` is true, and that has neither a false
:attr:`condition <bdb.Breakpoint.cond>` nor positive
:attr:`ignore <bdb.Breakpoint.ignore>` count. The *flag*, meaning that a
temporary breakpoint should be deleted, is False only when the
temporary breakpoint should be deleted, is ``False`` only when the
:attr:`cond <bdb.Breakpoint.cond>` cannot be evaluated (in which case,
:attr:`ignore <bdb.Breakpoint.ignore>` count is ignored).

If no such entry exists, then (None, None) is returned.
If no such entry exists, then ``(None, None)`` is returned.


.. function:: set_trace()
Expand Down
6 changes: 3 additions & 3 deletions Doc/library/compileall.rst
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ Public functions
The *invalidation_mode* parameter was added.

.. versionchanged:: 3.7.2
The *invalidation_mode* parameter's default value is updated to None.
The *invalidation_mode* parameter's default value is updated to ``None``.

.. versionchanged:: 3.8
Setting *workers* to 0 now chooses the optimal number of cores.
Expand Down Expand Up @@ -289,7 +289,7 @@ Public functions
The *invalidation_mode* parameter was added.

.. versionchanged:: 3.7.2
The *invalidation_mode* parameter's default value is updated to None.
The *invalidation_mode* parameter's default value is updated to ``None``.

.. versionchanged:: 3.9
Added *stripdir*, *prependdir*, *limit_sl_dest* and *hardlink_dupes* arguments.
Expand Down Expand Up @@ -318,7 +318,7 @@ Public functions
The *invalidation_mode* parameter was added.

.. versionchanged:: 3.7.2
The *invalidation_mode* parameter's default value is updated to None.
The *invalidation_mode* parameter's default value is updated to ``None``.

To force a recompile of all the :file:`.py` files in the :file:`Lib/`
subdirectory and all its subdirectories::
Expand Down
4 changes: 2 additions & 2 deletions Doc/library/csv.rst
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,8 @@ The :mod:`csv` module defines the following constants:
``None``. This is similar to :data:`QUOTE_ALL`, except that if a
field value is ``None`` an empty (unquoted) string is written.

Instructs :class:`reader` objects to interpret an empty (unquoted) field as None and
to otherwise behave as :data:`QUOTE_ALL`.
Instructs :class:`reader` objects to interpret an empty (unquoted) field
as ``None`` and to otherwise behave as :data:`QUOTE_ALL`.

.. versionadded:: 3.12

Expand Down
2 changes: 1 addition & 1 deletion Doc/library/dataclasses.rst
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ Module contents
generated equality and comparison methods (:meth:`~object.__eq__`,
:meth:`~object.__gt__`, et al.).

- *metadata*: This can be a mapping or None. None is treated as
- *metadata*: This can be a mapping or ``None``. ``None`` is treated as
an empty dict. This value is wrapped in
:func:`~types.MappingProxyType` to make it read-only, and exposed
on the :class:`Field` object. It is not used at all by Data
Expand Down
2 changes: 1 addition & 1 deletion Doc/library/functools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ The :mod:`functools` module defines the following functions:
.. versionadded:: 3.2

.. versionchanged:: 3.4
Returning NotImplemented from the underlying comparison function for
Returning ``NotImplemented`` from the underlying comparison function for
unrecognised types is now supported.

.. function:: partial(func, /, *args, **keywords)
Expand Down
2 changes: 1 addition & 1 deletion Doc/library/gc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ The :mod:`gc` module provides the following functions:
.. function:: get_objects(generation=None)

Returns a list of all objects tracked by the collector, excluding the list
returned. If *generation* is not None, return only the objects tracked by
returned. If *generation* is not ``None``, return only the objects tracked by
the collector that are in that generation.

.. versionchanged:: 3.8
Expand Down
6 changes: 3 additions & 3 deletions Doc/library/imaplib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ base class:
initialized. If *host* is not specified, ``''`` (the local host) is used. If
*port* is omitted, the standard IMAP4 port (143) is used. The optional *timeout*
parameter specifies a timeout in seconds for the connection attempt.
If timeout is not given or is None, the global default socket timeout is used.
If timeout is not given or is ``None``, the global default socket timeout is used.

The :class:`IMAP4` class supports the :keyword:`with` statement. When used
like this, the IMAP4 ``LOGOUT`` command is issued automatically when the
Expand Down Expand Up @@ -97,7 +97,7 @@ There's also a subclass for secure connections:
best practices.

The optional *timeout* parameter specifies a timeout in seconds for the
connection attempt. If timeout is not given or is None, the global default
connection attempt. If timeout is not given or is ``None``, the global default
socket timeout is used.

.. versionchanged:: 3.3
Expand Down Expand Up @@ -360,7 +360,7 @@ An :class:`IMAP4` instance has the following methods:

Opens socket to *port* at *host*. The optional *timeout* parameter
specifies a timeout in seconds for the connection attempt.
If timeout is not given or is None, the global default socket timeout
If timeout is not given or is ``None``, the global default socket timeout
is used. Also note that if the *timeout* parameter is set to be zero,
it will raise a :class:`ValueError` to reject creating a non-blocking socket.
This method is implicitly called by the :class:`IMAP4` constructor.
Expand Down
4 changes: 2 additions & 2 deletions Doc/library/importlib.resources.abc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@

.. abstractmethod:: is_dir()

Return True if self is a directory.
Return ``True`` if self is a directory.

.. abstractmethod:: is_file()

Return True if self is a file.
Return ``True`` if self is a file.

.. abstractmethod:: joinpath(*pathsegments)

Expand Down
2 changes: 1 addition & 1 deletion Doc/library/logging.handlers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ and :meth:`flush` methods).

:param stream: The stream that the handler should use.

:return: the old stream, if the stream was changed, or *None* if it wasn't.
:return: the old stream, if the stream was changed, or ``None`` if it wasn't.

.. versionadded:: 3.7

Expand Down
2 changes: 1 addition & 1 deletion Doc/library/math.rst
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ Number-theoretic and representation functions
Evaluates to ``n! / (n - k)!`` when ``k <= n`` and evaluates
to zero when ``k > n``.

If *k* is not specified or is None, then *k* defaults to *n*
If *k* is not specified or is ``None``, then *k* defaults to *n*
and the function returns ``n!``.

Raises :exc:`TypeError` if either of the arguments are not integers.
Expand Down
8 changes: 4 additions & 4 deletions Doc/library/multiprocessing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2472,9 +2472,9 @@ multiple connections at the same time.
generally be omitted since it can usually be inferred from the format of
*address*. (See :ref:`multiprocessing-address-formats`)

If *authkey* is given and not None, it should be a byte string and will be
If *authkey* is given and not ``None``, it should be a byte string and will be
used as the secret key for an HMAC-based authentication challenge. No
authentication is done if *authkey* is None.
authentication is done if *authkey* is ``None``.
:exc:`~multiprocessing.AuthenticationError` is raised if authentication fails.
See :ref:`multiprocessing-auth-keys`.

Expand Down Expand Up @@ -2507,9 +2507,9 @@ multiple connections at the same time.
to the :meth:`~socket.socket.listen` method of the socket once it has been
bound.

If *authkey* is given and not None, it should be a byte string and will be
If *authkey* is given and not ``None``, it should be a byte string and will be
used as the secret key for an HMAC-based authentication challenge. No
authentication is done if *authkey* is None.
authentication is done if *authkey* is ``None``.
:exc:`~multiprocessing.AuthenticationError` is raised if authentication fails.
See :ref:`multiprocessing-auth-keys`.

Expand Down
4 changes: 2 additions & 2 deletions Doc/library/os.rst
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ as internal buffering of data.

Copy *count* bytes from file descriptor *src*, starting from offset
*offset_src*, to file descriptor *dst*, starting from offset *offset_dst*.
If *offset_src* is None, then *src* is read from the current position;
If *offset_src* is ``None``, then *src* is read from the current position;
respectively for *offset_dst*.

In Linux kernel older than 5.3, the files pointed to by *src* and *dst*
Expand Down Expand Up @@ -1664,7 +1664,7 @@ or `the MSDN <https://msdn.microsoft.com/en-us/library/z0kc8e3z.aspx>`_ on Windo
Transfer *count* bytes from file descriptor *src*, starting from offset
*offset_src*, to file descriptor *dst*, starting from offset *offset_dst*.
At least one of the file descriptors must refer to a pipe. If *offset_src*
is None, then *src* is read from the current position; respectively for
is ``None``, then *src* is read from the current position; respectively for
*offset_dst*. The offset associated to the file descriptor that refers to a
pipe must be ``None``. The files pointed to by *src* and *dst* must reside in
the same filesystem, otherwise an :exc:`OSError` is raised with
Expand Down
4 changes: 2 additions & 2 deletions Doc/library/pathlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,8 @@ Pure paths provide the following methods and properties:
raise ValueError(error_message.format(str(self), str(formatted)))
ValueError: '/etc/passwd' is not in the subpath of '/usr' OR one path is relative and the other is absolute.

When *walk_up* is False (the default), the path must start with *other*.
When the argument is True, ``..`` entries may be added to form the
When *walk_up* is false (the default), the path must start with *other*.
When the argument is true, ``..`` entries may be added to form the
relative path. In all other cases, such as the paths referencing
different drives, :exc:`ValueError` is raised.::

Expand Down
16 changes: 8 additions & 8 deletions Doc/library/pickle.rst
Original file line number Diff line number Diff line change
Expand Up @@ -314,16 +314,16 @@ The :mod:`pickle` module exports three classes, :class:`Pickler`,
map the new Python 3 names to the old module names used in Python 2, so
that the pickle data stream is readable with Python 2.

If *buffer_callback* is None (the default), buffer views are
If *buffer_callback* is ``None`` (the default), buffer views are
serialized into *file* as part of the pickle stream.

If *buffer_callback* is not None, then it can be called any number
If *buffer_callback* is not ``None``, then it can be called any number
of times with a buffer view. If the callback returns a false value
(such as None), the given buffer is :ref:`out-of-band <pickle-oob>`;
(such as ``None``), the given buffer is :ref:`out-of-band <pickle-oob>`;
otherwise the buffer is serialized in-band, i.e. inside the pickle stream.

It is an error if *buffer_callback* is not None and *protocol* is
None or smaller than 5.
It is an error if *buffer_callback* is not ``None`` and *protocol* is
``None`` or smaller than 5.

.. versionchanged:: 3.8
The *buffer_callback* argument was added.
Expand Down Expand Up @@ -416,12 +416,12 @@ The :mod:`pickle` module exports three classes, :class:`Pickler`,
instances of :class:`~datetime.datetime`, :class:`~datetime.date` and
:class:`~datetime.time` pickled by Python 2.

If *buffers* is None (the default), then all data necessary for
If *buffers* is ``None`` (the default), then all data necessary for
deserialization must be contained in the pickle stream. This means
that the *buffer_callback* argument was None when a :class:`Pickler`
that the *buffer_callback* argument was ``None`` when a :class:`Pickler`
was instantiated (or when :func:`dump` or :func:`dumps` was called).

If *buffers* is not None, it should be an iterable of buffer-enabled
If *buffers* is not ``None``, it should be an iterable of buffer-enabled
objects that is consumed each time the pickle stream references
an :ref:`out-of-band <pickle-oob>` buffer view. Such buffers have been
given in order to the *buffer_callback* of a Pickler object.
Expand Down
2 changes: 1 addition & 1 deletion Doc/library/pyclbr.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ Class Objects

.. attribute:: parent

For top-level classes, None. For nested classes, the parent.
For top-level classes, ``None``. For nested classes, the parent.

.. versionadded:: 3.7

Expand Down
2 changes: 1 addition & 1 deletion Doc/library/statistics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ However, for reading convenience, most of the examples show sorted sequences.
.. function:: harmonic_mean(data, weights=None)

Return the harmonic mean of *data*, a sequence or iterable of
real-valued numbers. If *weights* is omitted or *None*, then
real-valued numbers. If *weights* is omitted or ``None``, then
equal weighting is assumed.

The harmonic mean is the reciprocal of the arithmetic :func:`mean` of the
Expand Down
2 changes: 1 addition & 1 deletion Doc/library/sys.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1684,7 +1684,7 @@ always available.
contain a tuple of (filename, line number, function name) tuples
describing the traceback where the coroutine object was created,
with the most recent call first. When disabled, ``cr_origin`` will
be None.
be ``None``.

To enable, pass a *depth* value greater than zero; this sets the
number of frames whose information will be captured. To disable,
Expand Down
2 changes: 1 addition & 1 deletion Doc/library/test.rst
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ The :mod:`test.support` module defines the following constants:

.. data:: Py_DEBUG

True if Python was built with the :c:macro:`Py_DEBUG` macro
``True`` if Python was built with the :c:macro:`Py_DEBUG` macro
defined, that is, if
Python was :ref:`built in debug mode <debug-build>`.

Expand Down
4 changes: 2 additions & 2 deletions Doc/library/tkinter.dnd.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ Selection of a target object occurs as follows:
#. Top-down search of area under mouse for target widget

* Target widget should have a callable *dnd_accept* attribute
* If *dnd_accept* is not present or returns None, search moves to parent widget
* If no target widget is found, then the target object is None
* If *dnd_accept* is not present or returns ``None``, search moves to parent widget
* If no target widget is found, then the target object is ``None``

2. Call to *<old_target>.dnd_leave(source, event)*
#. Call to *<new_target>.dnd_enter(source, event)*
Expand Down
4 changes: 2 additions & 2 deletions Doc/library/tty.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ The :mod:`tty` module defines the following functions:
is saved before setting *fd* to raw mode; this value is returned.

.. versionchanged:: 3.12
The return value is now the original tty attributes, instead of None.
The return value is now the original tty attributes, instead of ``None``.


.. function:: setcbreak(fd, when=termios.TCSAFLUSH)
Expand All @@ -67,7 +67,7 @@ The :mod:`tty` module defines the following functions:
the minimum input to 1 byte with no delay.

.. versionchanged:: 3.12
The return value is now the original tty attributes, instead of None.
The return value is now the original tty attributes, instead of ``None``.

.. versionchanged:: 3.12.2
The ``ICRNL`` flag is no longer cleared. This restores the behavior
Expand Down
Loading

0 comments on commit 392bd67

Please sign in to comment.