Skip to content

Commit

Permalink
Merge branch 'main' into nested_functions
Browse files Browse the repository at this point in the history
  • Loading branch information
iritkatriel authored Apr 22, 2024
2 parents 17ada5a + 78ba4cb commit 66f10a9
Show file tree
Hide file tree
Showing 131 changed files with 2,703 additions and 748 deletions.
4 changes: 4 additions & 0 deletions Doc/bugs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ have a suggestion on how to fix it, include that as well.
You can also open a discussion item on our
`Documentation Discourse forum <https://discuss.python.org/c/documentation/26>`_.

If you find a bug in the theme (HTML / CSS / JavaScript) of the
documentation, please submit a bug report on the `python-doc-theme bug
tracker <https://github.com/python/python-docs-theme>`_.

If you're short on time, you can also email documentation bug reports to
[email protected] (behavioral bugs can be sent to [email protected]).
'docs@' is a mailing list run by volunteers; your request will be noticed,
Expand Down
130 changes: 130 additions & 0 deletions Doc/c-api/init.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ The following functions can be safely called before Python is initialized:
* :c:func:`PyMem_SetAllocator`
* :c:func:`PyMem_SetupDebugHooks`
* :c:func:`PyObject_SetArenaAllocator`
* :c:func:`Py_SetProgramName`
* :c:func:`Py_SetPythonHome`
* :c:func:`PySys_ResetWarnOptions`

* Informative functions:
Expand Down Expand Up @@ -426,6 +428,34 @@ Process-wide parameters
=======================
.. c:function:: void Py_SetProgramName(const wchar_t *name)
.. index::
single: Py_Initialize()
single: main()
single: Py_GetPath()
This API is kept for backward compatibility: setting
:c:member:`PyConfig.program_name` should be used instead, see :ref:`Python
Initialization Configuration <init-config>`.
This function should be called before :c:func:`Py_Initialize` is called for
the first time, if it is called at all. It tells the interpreter the value
of the ``argv[0]`` argument to the :c:func:`main` function of the program
(converted to wide characters).
This is used by :c:func:`Py_GetPath` and some other functions below to find
the Python run-time libraries relative to the interpreter executable. The
default value is ``'python'``. The argument should point to a
zero-terminated wide character string in static storage whose contents will not
change for the duration of the program's execution. No code in the Python
interpreter will change the contents of this storage.
Use :c:func:`Py_DecodeLocale` to decode a bytes string to get a
:c:expr:`wchar_*` string.
.. deprecated:: 3.11
.. c:function:: wchar_t* Py_GetProgramName()
Return the program name set with :c:member:`PyConfig.program_name`, or the default.
Expand Down Expand Up @@ -627,6 +657,106 @@ Process-wide parameters
``sys.version``.
.. c:function:: void PySys_SetArgvEx(int argc, wchar_t **argv, int updatepath)
.. index::
single: main()
single: Py_FatalError()
single: argv (in module sys)
This API is kept for backward compatibility: setting
:c:member:`PyConfig.argv`, :c:member:`PyConfig.parse_argv` and
:c:member:`PyConfig.safe_path` should be used instead, see :ref:`Python
Initialization Configuration <init-config>`.
Set :data:`sys.argv` based on *argc* and *argv*. These parameters are
similar to those passed to the program's :c:func:`main` function with the
difference that the first entry should refer to the script file to be
executed rather than the executable hosting the Python interpreter. If there
isn't a script that will be run, the first entry in *argv* can be an empty
string. If this function fails to initialize :data:`sys.argv`, a fatal
condition is signalled using :c:func:`Py_FatalError`.
If *updatepath* is zero, this is all the function does. If *updatepath*
is non-zero, the function also modifies :data:`sys.path` according to the
following algorithm:
- If the name of an existing script is passed in ``argv[0]``, the absolute
path of the directory where the script is located is prepended to
:data:`sys.path`.
- Otherwise (that is, if *argc* is ``0`` or ``argv[0]`` doesn't point
to an existing file name), an empty string is prepended to
:data:`sys.path`, which is the same as prepending the current working
directory (``"."``).
Use :c:func:`Py_DecodeLocale` to decode a bytes string to get a
:c:expr:`wchar_*` string.
See also :c:member:`PyConfig.orig_argv` and :c:member:`PyConfig.argv`
members of the :ref:`Python Initialization Configuration <init-config>`.
.. note::
It is recommended that applications embedding the Python interpreter
for purposes other than executing a single script pass ``0`` as *updatepath*,
and update :data:`sys.path` themselves if desired.
See :cve:`2008-5983`.
On versions before 3.1.3, you can achieve the same effect by manually
popping the first :data:`sys.path` element after having called
:c:func:`PySys_SetArgv`, for example using::
PyRun_SimpleString("import sys; sys.path.pop(0)\n");
.. versionadded:: 3.1.3
.. XXX impl. doesn't seem consistent in allowing ``0``/``NULL`` for the params;
check w/ Guido.
.. deprecated:: 3.11
.. c:function:: void PySys_SetArgv(int argc, wchar_t **argv)
This API is kept for backward compatibility: setting
:c:member:`PyConfig.argv` and :c:member:`PyConfig.parse_argv` should be used
instead, see :ref:`Python Initialization Configuration <init-config>`.
This function works like :c:func:`PySys_SetArgvEx` with *updatepath* set
to ``1`` unless the :program:`python` interpreter was started with the
:option:`-I`.
Use :c:func:`Py_DecodeLocale` to decode a bytes string to get a
:c:expr:`wchar_*` string.
See also :c:member:`PyConfig.orig_argv` and :c:member:`PyConfig.argv`
members of the :ref:`Python Initialization Configuration <init-config>`.
.. versionchanged:: 3.4 The *updatepath* value depends on :option:`-I`.
.. deprecated:: 3.11
.. c:function:: void Py_SetPythonHome(const wchar_t *home)
This API is kept for backward compatibility: setting
:c:member:`PyConfig.home` should be used instead, see :ref:`Python
Initialization Configuration <init-config>`.
Set the default "home" directory, that is, the location of the standard
Python libraries. See :envvar:`PYTHONHOME` for the meaning of the
argument string.
The argument should point to a zero-terminated character string in static
storage whose contents will not change for the duration of the program's
execution. No code in the Python interpreter will change the contents of
this storage.
Use :c:func:`Py_DecodeLocale` to decode a bytes string to get a
:c:expr:`wchar_*` string.
.. deprecated:: 3.11
.. c:function:: wchar_t* Py_GetPythonHome()
Return the default "home", that is, the value set by
Expand Down
6 changes: 6 additions & 0 deletions Doc/c-api/tuple.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ Tuple Objects
Return the object at position *pos* in the tuple pointed to by *p*. If *pos* is
negative or out of bounds, return ``NULL`` and set an :exc:`IndexError` exception.
The returned reference is borrowed from the tuple *p*
(that is: it is only valid as long as you hold a reference to *p*).
To get a :term:`strong reference`, use
:c:func:`Py_NewRef(PyTuple_GetItem(...)) <Py_NewRef>`
or :c:func:`PySequence_GetItem`.
.. c:function:: PyObject* PyTuple_GET_ITEM(PyObject *p, Py_ssize_t pos)
Expand Down
3 changes: 2 additions & 1 deletion Doc/c-api/typeobj.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,8 @@ and :c:data:`PyType_Type` effectively act as defaults.)
the type, and the type object is INCREF'ed when a new instance is created, and
DECREF'ed when an instance is destroyed (this does not apply to instances of
subtypes; only the type referenced by the instance's ob_type gets INCREF'ed or
DECREF'ed).
DECREF'ed). Heap types should also :ref:`support garbage collection <supporting-cycle-detection>`
as they can form a reference cycle with their own module object.

**Inheritance:**

Expand Down
4 changes: 4 additions & 0 deletions Doc/data/stable_abi.dat

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

5 changes: 3 additions & 2 deletions Doc/library/ast.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2536,7 +2536,8 @@ to stdout. Otherwise, the content is read from stdin.
code that generated them. This is helpful for tools that make source code
transformations.

`leoAst.py <https://leoeditor.com/appendices.html#leoast-py>`_ unifies the
`leoAst.py <https://leo-editor.github.io/leo-editor/appendices.html#leoast-py>`_
unifies the
token-based and parse-tree-based views of python programs by inserting
two-way links between tokens and ast nodes.

Expand All @@ -2548,4 +2549,4 @@ to stdout. Otherwise, the content is read from stdin.
`Parso <https://parso.readthedocs.io>`_ is a Python parser that supports
error recovery and round-trip parsing for different Python versions (in
multiple Python versions). Parso is also able to list multiple syntax errors
in your python file.
in your Python file.
15 changes: 14 additions & 1 deletion Doc/library/bz2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ The :mod:`bz2` module contains:
and :meth:`~io.IOBase.truncate`.
Iteration and the :keyword:`with` statement are supported.

:class:`BZ2File` also provides the following methods:
:class:`BZ2File` also provides the following methods and attributes:

.. method:: peek([n])

Expand Down Expand Up @@ -148,6 +148,19 @@ The :mod:`bz2` module contains:

.. versionadded:: 3.3

.. attribute:: mode

``'rb'`` for reading and ``'wb'`` for writing.

.. versionadded:: 3.13

.. attribute:: name

The bzip2 file name. Equivalent to the :attr:`~io.FileIO.name`
attribute of the underlying :term:`file object`.

.. versionadded:: 3.13


.. versionchanged:: 3.1
Support for the :keyword:`with` statement was added.
Expand Down
16 changes: 8 additions & 8 deletions Doc/library/ctypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2077,13 +2077,13 @@ Utility functions
Does the same as the C ``sizeof`` operator.


.. function:: string_at(address, size=-1)
.. function:: string_at(ptr, size=-1)

This function returns the C string starting at memory address *address* as a bytes
object. If size is specified, it is used as size, otherwise the string is assumed
Return the byte string at *void \*ptr*.
If *size* is specified, it is used as size, otherwise the string is assumed
to be zero-terminated.

.. audit-event:: ctypes.string_at address,size ctypes.string_at
.. audit-event:: ctypes.string_at ptr,size ctypes.string_at


.. function:: WinError(code=None, descr=None)
Expand All @@ -2099,14 +2099,14 @@ Utility functions
alias of :exc:`OSError`.


.. function:: wstring_at(address, size=-1)
.. function:: wstring_at(ptr, size=-1)

This function returns the wide character string starting at memory address
*address* as a string. If *size* is specified, it is used as the number of
Return the wide-character string at *void \*ptr*.
If *size* is specified, it is used as the number of
characters of the string, otherwise the string is assumed to be
zero-terminated.

.. audit-event:: ctypes.wstring_at address,size ctypes.wstring_at
.. audit-event:: ctypes.wstring_at ptr,size ctypes.wstring_at


.. _ctypes-data-types:
Expand Down
6 changes: 3 additions & 3 deletions Doc/library/doctest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -800,18 +800,18 @@ guarantee about output. For example, when printing a set, Python doesn't
guarantee that the element is printed in any particular order, so a test like ::

>>> foo()
{"Hermione", "Harry"}
{"spam", "eggs"}

is vulnerable! One workaround is to do ::

>>> foo() == {"Hermione", "Harry"}
>>> foo() == {"spam", "eggs"}
True

instead. Another is to do ::

>>> d = sorted(foo())
>>> d
['Harry', 'Hermione']
['eggs', 'spam']

There are others, but you get the idea.

Expand Down
15 changes: 11 additions & 4 deletions Doc/library/gzip.rst
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ The module defines the following items:

.. versionadded:: 3.2

.. attribute:: mode

``'rb'`` for reading and ``'wb'`` for writing.

.. versionchanged:: 3.13
In previous versions it was an integer ``1`` or ``2``.

.. attribute:: mtime

When decompressing, this attribute is set to the last timestamp in the most
Expand Down Expand Up @@ -168,14 +175,14 @@ The module defines the following items:
.. versionchanged:: 3.6
Accepts a :term:`path-like object`.

.. versionchanged:: 3.12
Remove the ``filename`` attribute, use the :attr:`~GzipFile.name`
attribute instead.

.. deprecated:: 3.9
Opening :class:`GzipFile` for writing without specifying the *mode*
argument is deprecated.

.. versionchanged:: 3.12
Remove the ``filename`` attribute, use the :attr:`~GzipFile.name`
attribute instead.


.. function:: compress(data, compresslevel=9, *, mtime=None)

Expand Down
16 changes: 15 additions & 1 deletion Doc/library/lzma.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Reading and writing compressed files
and :meth:`~io.IOBase.truncate`.
Iteration and the :keyword:`with` statement are supported.

The following method is also provided:
The following method and attributes are also provided:

.. method:: peek(size=-1)

Expand All @@ -117,6 +117,20 @@ Reading and writing compressed files
file object (e.g. if the :class:`LZMAFile` was constructed by passing a
file object for *filename*).

.. attribute:: mode

``'rb'`` for reading and ``'wb'`` for writing.

.. versionadded:: 3.13

.. attribute:: name

The lzma file name. Equivalent to the :attr:`~io.FileIO.name`
attribute of the underlying :term:`file object`.

.. versionadded:: 3.13


.. versionchanged:: 3.4
Added support for the ``"x"`` and ``"xb"`` modes.

Expand Down
5 changes: 2 additions & 3 deletions Doc/library/pprint.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ such as files, sockets or classes are included, as well as many other
objects which are not representable as Python literals.

The formatted representation keeps objects on a single line if it can, and
breaks them onto multiple lines if they don't fit within the allowed width.
Construct :class:`PrettyPrinter` objects explicitly if you need to adjust the
width constraint.
breaks them onto multiple lines if they don't fit within the allowed width,
adjustable by the *width* parameter defaulting to 80 characters.

Dictionaries are sorted by key before the display is computed.

Expand Down
Loading

0 comments on commit 66f10a9

Please sign in to comment.