Skip to content

Commit

Permalink
Merge branch 'main' into sigdocs
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra authored Oct 9, 2024
2 parents c549c70 + b502573 commit e448b82
Show file tree
Hide file tree
Showing 247 changed files with 12,857 additions and 15,926 deletions.
6 changes: 4 additions & 2 deletions Doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,15 @@ serve:

# for development releases: always build
.PHONY: autobuild-dev
autobuild-dev: DISTVERSION = $(shell $(PYTHON) tools/extensions/patchlevel.py --short)
autobuild-dev:
$(MAKE) dist-no-html SPHINXOPTS='$(SPHINXOPTS) -Ea -A daily=1'
$(MAKE) dist-no-html SPHINXOPTS='$(SPHINXOPTS) -Ea -A daily=1' DISTVERSION=$(DISTVERSION)

# for HTML-only rebuilds
.PHONY: autobuild-dev-html
autobuild-dev-html: DISTVERSION = $(shell $(PYTHON) tools/extensions/patchlevel.py --short)
autobuild-dev-html:
$(MAKE) dist-html SPHINXOPTS='$(SPHINXOPTS) -Ea -A daily=1'
$(MAKE) dist-html SPHINXOPTS='$(SPHINXOPTS) -Ea -A daily=1' DISTVERSION=$(DISTVERSION)

# for stable releases: only build if not in pre-release stage (alpha, beta)
# release candidate downloads are okay, since the stable tree can be in that stage
Expand Down
9 changes: 6 additions & 3 deletions Doc/c-api/code.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ bound into a function.
.. c:function:: Py_ssize_t PyCode_GetNumFree(PyCodeObject *co)
Return the number of free variables in a code object.
Return the number of :term:`free (closure) variables <closure variable>`
in a code object.
.. c:function:: int PyUnstable_Code_GetFirstFree(PyCodeObject *co)
Return the position of the first free variable in a code object.
Return the position of the first :term:`free (closure) variable <closure variable>`
in a code object.
.. versionchanged:: 3.13
Expand Down Expand Up @@ -144,7 +146,8 @@ bound into a function.
Equivalent to the Python code ``getattr(co, 'co_freevars')``.
Returns a new reference to a :c:type:`PyTupleObject` containing the names of
the free variables. On error, ``NULL`` is returned and an exception is raised.
the :term:`free (closure) variables <closure variable>`. On error, ``NULL`` is returned
and an exception is raised.
.. versionadded:: 3.11
Expand Down
240 changes: 203 additions & 37 deletions Doc/c-api/init.rst

Large diffs are not rendered by default.

29 changes: 4 additions & 25 deletions Doc/c-api/init_config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1356,14 +1356,13 @@ the :option:`-X` command line option.
The ``show_alloc_count`` field has been removed.
.. _init-from-config:
Initialization with PyConfig
----------------------------
Function to initialize Python:
.. c:function:: PyStatus Py_InitializeFromConfig(const PyConfig *config)
Initialize Python from *config* configuration.
Initializing the interpreter from a populated configuration struct is handled
by calling :c:func:`Py_InitializeFromConfig`.
The caller is responsible to handle exceptions (error or exit) using
:c:func:`PyStatus_Exception` and :c:func:`Py_ExitStatusException`.
Expand Down Expand Up @@ -1835,26 +1834,6 @@ return ``-1`` on error:
}
Py_RunMain()
============
.. c:function:: int Py_RunMain(void)
Execute the command (:c:member:`PyConfig.run_command`), the script
(:c:member:`PyConfig.run_filename`) or the module
(:c:member:`PyConfig.run_module`) specified on the command line or in the
configuration.
By default and when if :option:`-i` option is used, run the REPL.
Finally, finalizes Python and returns an exit status that can be passed to
the ``exit()`` function.
See :ref:`Python Configuration <init-python-config>` for an example of
customized Python always running in isolated mode using
:c:func:`Py_RunMain`.
Runtime Python configuration API
================================
Expand Down
3 changes: 2 additions & 1 deletion Doc/c-api/tuple.rst
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ type.
.. c:member:: const char *name
Name of the struct sequence type.
Fully qualified name of the type; null-terminated UTF-8 encoded.
The name must contain the module name.
.. c:member:: const char *doc
Expand Down
25 changes: 25 additions & 0 deletions Doc/c-api/unicode.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,31 @@ They all return ``NULL`` or ``-1`` if an exception occurs.
This function returns ``-1`` upon failure, so one should call
:c:func:`PyErr_Occurred` to check for errors.
.. seealso::
The :c:func:`PyUnicode_Equal` function.
.. c:function:: int PyUnicode_Equal(PyObject *a, PyObject *b)
Test if two strings are equal:
* Return ``1`` if *a* is equal to *b*.
* Return ``0`` if *a* is not equal to *b*.
* Set a :exc:`TypeError` exception and return ``-1`` if *a* or *b* is not a
:class:`str` object.
The function always succeeds if *a* and *b* are :class:`str` objects.
The function works for :class:`str` subclasses, but does not honor custom
``__eq__()`` method.
.. seealso::
The :c:func:`PyUnicode_Compare` function.
.. versionadded:: 3.14
.. c:function:: int PyUnicode_EqualToUTF8AndSize(PyObject *unicode, const char *string, Py_ssize_t size)
Expand Down
24 changes: 0 additions & 24 deletions Doc/c-api/veryhigh.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,6 @@ are only passed to these functions if it is certain that they were created by
the same library that the Python runtime is using.


.. c:function:: int Py_Main(int argc, wchar_t **argv)
The main program for the standard interpreter. This is made available for
programs which embed Python. The *argc* and *argv* parameters should be
prepared exactly as those which are passed to a C program's :c:func:`main`
function (converted to wchar_t according to the user's locale). It is
important to note that the argument list may be modified (but the contents of
the strings pointed to by the argument list are not). The return value will
be ``0`` if the interpreter exits normally (i.e., without an exception),
``1`` if the interpreter exits due to an exception, or ``2`` if the parameter
list does not represent a valid Python command line.
Note that if an otherwise unhandled :exc:`SystemExit` is raised, this
function will not return ``1``, but exit the process, as long as
:c:member:`PyConfig.inspect` is zero.
.. c:function:: int Py_BytesMain(int argc, char **argv)
Similar to :c:func:`Py_Main` but *argv* is an array of bytes strings.
.. versionadded:: 3.8
.. c:function:: int PyRun_AnyFile(FILE *fp, const char *filename)
This is a simplified interface to :c:func:`PyRun_AnyFileExFlags` below, leaving
Expand Down
1 change: 1 addition & 0 deletions Doc/data/stable_abi.dat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 34 additions & 9 deletions Doc/glossary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,28 @@ Glossary
A variable defined in a class and intended to be modified only at
class level (i.e., not in an instance of the class).

closure variable
A :term:`free variable` referenced from a :term:`nested scope` that is defined in an outer
scope rather than being resolved at runtime from the globals or builtin namespaces.
May be explicitly defined with the :keyword:`nonlocal` keyword to allow write access,
or implicitly defined if the variable is only being read.

For example, in the ``inner`` function in the following code, both ``x`` and ``print`` are
:term:`free variables <free variable>`, but only ``x`` is a *closure variable*::

def outer():
x = 0
def inner():
nonlocal x
x += 1
print(x)
return inner

Due to the :attr:`codeobject.co_freevars` attribute (which, despite its name, only
includes the names of closure variables rather than listing all referenced free
variables), the more general :term:`free variable` term is sometimes used even
when the intended meaning is to refer specifically to closure variables.

complex number
An extension of the familiar real number system in which all numbers are
expressed as a sum of a real part and an imaginary part. Imaginary
Expand Down Expand Up @@ -454,6 +476,13 @@ Glossary
the :term:`global interpreter lock` which allows only one thread to
execute Python bytecode at a time. See :pep:`703`.

free variable
Formally, as defined in the :ref:`language execution model <bind_names>`, a free
variable is any variable used in a namespace which is not a local variable in that
namespace. See :term:`closure variable` for an example.
Pragmatically, due to the name of the :attr:`codeobject.co_freevars` attribute,
the term is also sometimes used as a synonym for :term:`closure variable`.

function
A series of statements which returns some value to a caller. It can also
be passed zero or more :term:`arguments <argument>` which may be used in
Expand Down Expand Up @@ -1160,16 +1189,12 @@ Glossary
(subscript) notation uses :class:`slice` objects internally.

soft deprecated
A soft deprecation can be used when using an API which should no longer
be used to write new code, but it remains safe to continue using it in
existing code. The API remains documented and tested, but will not be
developed further (no enhancement).

The main difference between a "soft" and a (regular) "hard" deprecation
is that the soft deprecation does not imply scheduling the removal of the
deprecated API.
A soft deprecated API should not be used in new code,
but it is safe for already existing code to use it.
The API remains documented and tested, but will not be enhanced further.

Another difference is that a soft deprecation does not issue a warning.
Soft deprecation, unlike normal deprecation, does not plan on removing the API
and will not emit warnings.

See `PEP 387: Soft Deprecation
<https://peps.python.org/pep-0387/#soft-deprecation>`_.
Expand Down
55 changes: 55 additions & 0 deletions Doc/howto/argparse-optparse.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
.. currentmodule:: argparse

.. _upgrading-optparse-code:

==========================
Upgrading optparse code
==========================

Originally, the :mod:`argparse` module had attempted to maintain compatibility
with :mod:`optparse`. However, :mod:`optparse` was difficult to extend
transparently, particularly with the changes required to support
``nargs=`` specifiers and better usage messages. When most everything in
:mod:`optparse` had either been copy-pasted over or monkey-patched, it no
longer seemed practical to try to maintain the backwards compatibility.

The :mod:`argparse` module improves on the :mod:`optparse`
module in a number of ways including:

* Handling positional arguments.
* Supporting subcommands.
* Allowing alternative option prefixes like ``+`` and ``/``.
* Handling zero-or-more and one-or-more style arguments.
* Producing more informative usage messages.
* Providing a much simpler interface for custom ``type`` and ``action``.

A partial upgrade path from :mod:`optparse` to :mod:`argparse`:

* Replace all :meth:`optparse.OptionParser.add_option` calls with
:meth:`ArgumentParser.add_argument` calls.

* Replace ``(options, args) = parser.parse_args()`` with ``args =
parser.parse_args()`` and add additional :meth:`ArgumentParser.add_argument`
calls for the positional arguments. Keep in mind that what was previously
called ``options``, now in the :mod:`argparse` context is called ``args``.

* Replace :meth:`optparse.OptionParser.disable_interspersed_args`
by using :meth:`~ArgumentParser.parse_intermixed_args` instead of
:meth:`~ArgumentParser.parse_args`.

* Replace callback actions and the ``callback_*`` keyword arguments with
``type`` or ``action`` arguments.

* Replace string names for ``type`` keyword arguments with the corresponding
type objects (e.g. int, float, complex, etc).

* Replace :class:`optparse.Values` with :class:`Namespace` and
:exc:`optparse.OptionError` and :exc:`optparse.OptionValueError` with
:exc:`ArgumentError`.

* Replace strings with implicit arguments such as ``%default`` or ``%prog`` with
the standard Python syntax to use dictionaries to format strings, that is,
``%(default)s`` and ``%(prog)s``.

* Replace the OptionParser constructor ``version`` argument with a call to
``parser.add_argument('--version', action='version', version='<the version>')``.
4 changes: 2 additions & 2 deletions Doc/howto/sockets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ mainloop of the web server::
(clientsocket, address) = serversocket.accept()
# now do something with the clientsocket
# in this case, we'll pretend this is a threaded server
ct = client_thread(clientsocket)
ct.run()
ct = make_client_thread(clientsocket)
ct.start()

There's actually 3 general ways in which this loop could work - dispatching a
thread to handle ``clientsocket``, create a new process to handle
Expand Down
9 changes: 2 additions & 7 deletions Doc/library/_thread.rst
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,8 @@ In addition to these methods, lock objects can also be used via the

.. index:: pair: module; signal

* Threads interact strangely with interrupts: the :exc:`KeyboardInterrupt`
exception will be received by an arbitrary thread. (When the :mod:`signal`
module is available, interrupts always go to the main thread.)
* Interrupts always go to the main thread (the :exc:`KeyboardInterrupt`
exception will be received by that thread.)

* Calling :func:`sys.exit` or raising the :exc:`SystemExit` exception is
equivalent to calling :func:`_thread.exit`.
Expand All @@ -229,7 +228,3 @@ In addition to these methods, lock objects can also be used via the
:keyword:`try` ... :keyword:`finally` clauses or executing object
destructors.

* When the main thread exits, it does not do any of its usual cleanup (except
that :keyword:`try` ... :keyword:`finally` clauses are honored), and the
standard I/O files are not flushed.

Loading

0 comments on commit e448b82

Please sign in to comment.