Skip to content

Commit 01fd166

Browse files
authored
Merge branch 'main' into docs-readline-repl
2 parents dbeef54 + 4867f71 commit 01fd166

File tree

74 files changed

+1872
-274
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1872
-274
lines changed

Doc/c-api/concrete.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ Other Objects
109109
descriptor.rst
110110
slice.rst
111111
memoryview.rst
112+
picklebuffer.rst
112113
weakref.rst
113114
capsule.rst
114115
frame.rst

Doc/c-api/dict.rst

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,3 +477,92 @@ Dictionary View Objects
477477
478478
Return true if *op* is an instance of a dictionary items view. This function
479479
always succeeds.
480+
481+
482+
Ordered Dictionaries
483+
^^^^^^^^^^^^^^^^^^^^
484+
485+
Python's C API provides interface for :class:`collections.OrderedDict` from C.
486+
Since Python 3.7, dictionaries are ordered by default, so there is usually
487+
little need for these functions; prefer ``PyDict*`` where possible.
488+
489+
490+
.. c:var:: PyTypeObject PyODict_Type
491+
492+
Type object for ordered dictionaries. This is the same object as
493+
:class:`collections.OrderedDict` in the Python layer.
494+
495+
496+
.. c:function:: int PyODict_Check(PyObject *od)
497+
498+
Return true if *od* is an ordered dictionary object or an instance of a
499+
subtype of the :class:`~collections.OrderedDict` type. This function
500+
always succeeds.
501+
502+
503+
.. c:function:: int PyODict_CheckExact(PyObject *od)
504+
505+
Return true if *od* is an ordered dictionary object, but not an instance of
506+
a subtype of the :class:`~collections.OrderedDict` type.
507+
This function always succeeds.
508+
509+
510+
.. c:var:: PyTypeObject PyODictKeys_Type
511+
512+
Analogous to :c:type:`PyDictKeys_Type` for ordered dictionaries.
513+
514+
515+
.. c:var:: PyTypeObject PyODictValues_Type
516+
517+
Analogous to :c:type:`PyDictValues_Type` for ordered dictionaries.
518+
519+
520+
.. c:var:: PyTypeObject PyODictItems_Type
521+
522+
Analogous to :c:type:`PyDictItems_Type` for ordered dictionaries.
523+
524+
525+
.. c:function:: PyObject *PyODict_New(void)
526+
527+
Return a new empty ordered dictionary, or ``NULL`` on failure.
528+
529+
This is analogous to :c:func:`PyDict_New`.
530+
531+
532+
.. c:function:: int PyODict_SetItem(PyObject *od, PyObject *key, PyObject *value)
533+
534+
Insert *value* into the ordered dictionary *od* with a key of *key*.
535+
Return ``0`` on success or ``-1`` with an exception set on failure.
536+
537+
This is analogous to :c:func:`PyDict_SetItem`.
538+
539+
540+
.. c:function:: int PyODict_DelItem(PyObject *od, PyObject *key)
541+
542+
Remove the entry in the ordered dictionary *od* with key *key*.
543+
Return ``0`` on success or ``-1`` with an exception set on failure.
544+
545+
This is analogous to :c:func:`PyDict_DelItem`.
546+
547+
548+
These are :term:`soft deprecated` aliases to ``PyDict`` APIs:
549+
550+
551+
.. list-table::
552+
:widths: auto
553+
:header-rows: 1
554+
555+
* * ``PyODict``
556+
* ``PyDict``
557+
* * .. c:macro:: PyODict_GetItem(od, key)
558+
* :c:func:`PyDict_GetItem`
559+
* * .. c:macro:: PyODict_GetItemWithError(od, key)
560+
* :c:func:`PyDict_GetItemWithError`
561+
* * .. c:macro:: PyODict_GetItemString(od, key)
562+
* :c:func:`PyDict_GetItemString`
563+
* * .. c:macro:: PyODict_Contains(od, key)
564+
* :c:func:`PyDict_Contains`
565+
* * .. c:macro:: PyODict_Size(od)
566+
* :c:func:`PyDict_Size`
567+
* * .. c:macro:: PyODict_SIZE(od)
568+
* :c:func:`PyDict_GET_SIZE`

Doc/c-api/intro.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,14 @@ complete listing.
183183

184184
.. versionadded:: 3.6
185185

186+
.. c:macro:: Py_MEMCPY(dest, src, n)
187+
188+
This is a :term:`soft deprecated` alias to :c:func:`!memcpy`.
189+
Use :c:func:`!memcpy` directly instead.
190+
191+
.. deprecated:: 3.14
192+
The macro is :term:`soft deprecated`.
193+
186194
.. c:macro:: Py_MIN(x, y)
187195
188196
Return the minimum value between ``x`` and ``y``.

Doc/c-api/iterator.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ Other Iterator Objects
108108
.. c:var:: PyTypeObject PyDictRevIterValue_Type
109109
.. c:var:: PyTypeObject PyDictIterItem_Type
110110
.. c:var:: PyTypeObject PyDictRevIterItem_Type
111+
.. c:var:: PyTypeObject PyODictIter_Type
111112
112113
Type objects for iterators of various built-in objects.
113114

Doc/c-api/picklebuffer.rst

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
.. highlight:: c
2+
3+
.. _picklebuffer-objects:
4+
5+
.. index::
6+
pair: object; PickleBuffer
7+
8+
Pickle buffer objects
9+
---------------------
10+
11+
.. versionadded:: 3.8
12+
13+
A :class:`pickle.PickleBuffer` object wraps a :ref:`buffer-providing object
14+
<bufferobjects>` for out-of-band data transfer with the :mod:`pickle` module.
15+
16+
17+
.. c:var:: PyTypeObject PyPickleBuffer_Type
18+
19+
This instance of :c:type:`PyTypeObject` represents the Python pickle buffer type.
20+
This is the same object as :class:`pickle.PickleBuffer` in the Python layer.
21+
22+
23+
.. c:function:: int PyPickleBuffer_Check(PyObject *op)
24+
25+
Return true if *op* is a pickle buffer instance.
26+
This function always succeeds.
27+
28+
29+
.. c:function:: PyObject *PyPickleBuffer_FromObject(PyObject *obj)
30+
31+
Create a pickle buffer from the object *obj*.
32+
33+
This function will fail if *obj* doesn't support the :ref:`buffer protocol <bufferobjects>`.
34+
35+
On success, return a new pickle buffer instance.
36+
On failure, set an exception and return ``NULL``.
37+
38+
Analogous to calling :class:`pickle.PickleBuffer` with *obj* in Python.
39+
40+
41+
.. c:function:: const Py_buffer *PyPickleBuffer_GetBuffer(PyObject *picklebuf)
42+
43+
Get a pointer to the underlying :c:type:`Py_buffer` that the pickle buffer wraps.
44+
45+
The returned pointer is valid as long as *picklebuf* is alive and has not been
46+
released. The caller must not modify or free the returned :c:type:`Py_buffer`.
47+
If the pickle buffer has been released, raise :exc:`ValueError`.
48+
49+
On success, return a pointer to the buffer view.
50+
On failure, set an exception and return ``NULL``.
51+
52+
53+
.. c:function:: int PyPickleBuffer_Release(PyObject *picklebuf)
54+
55+
Release the underlying buffer held by the pickle buffer.
56+
57+
Return ``0`` on success. On failure, set an exception and return ``-1``.
58+
59+
Analogous to calling :meth:`pickle.PickleBuffer.release` in Python.

Doc/c-api/structures.rst

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,25 @@ definition with the same method name.
447447
slot. This is helpful because calls to PyCFunctions are optimized more
448448
than wrapper object calls.
449449
450+
451+
.. c:var:: PyTypeObject PyCMethod_Type
452+
453+
The type object corresponding to Python C method objects. This is
454+
available as :class:`types.BuiltinMethodType` in the Python layer.
455+
456+
457+
.. c:function:: int PyCMethod_Check(PyObject *op)
458+
459+
Return true if *op* is an instance of the :c:type:`PyCMethod_Type` type
460+
or a subtype of it. This function always succeeds.
461+
462+
463+
.. c:function:: int PyCMethod_CheckExact(PyObject *op)
464+
465+
This is the same as :c:func:`PyCMethod_Check`, but does not account for
466+
subtypes.
467+
468+
450469
.. c:function:: PyObject * PyCMethod_New(PyMethodDef *ml, PyObject *self, PyObject *module, PyTypeObject *cls)
451470
452471
Turn *ml* into a Python :term:`callable` object.
@@ -472,6 +491,24 @@ definition with the same method name.
472491
.. versionadded:: 3.9
473492
474493
494+
.. c:var:: PyTypeObject PyCFunction_Type
495+
496+
The type object corresponding to Python C function objects. This is
497+
available as :class:`types.BuiltinFunctionType` in the Python layer.
498+
499+
500+
.. c:function:: int PyCFunction_Check(PyObject *op)
501+
502+
Return true if *op* is an instance of the :c:type:`PyCFunction_Type` type
503+
or a subtype of it. This function always succeeds.
504+
505+
506+
.. c:function:: int PyCFunction_CheckExact(PyObject *op)
507+
508+
This is the same as :c:func:`PyCFunction_Check`, but does not account for
509+
subtypes.
510+
511+
475512
.. c:function:: PyObject * PyCFunction_NewEx(PyMethodDef *ml, PyObject *self, PyObject *module)
476513
477514
Equivalent to ``PyCMethod_New(ml, self, module, NULL)``.
@@ -482,6 +519,62 @@ definition with the same method name.
482519
Equivalent to ``PyCMethod_New(ml, self, NULL, NULL)``.
483520
484521
522+
.. c:function:: int PyCFunction_GetFlags(PyObject *func)
523+
524+
Get the function's flags on *func* as they were passed to
525+
:c:member:`~PyMethodDef.ml_flags`.
526+
527+
If *func* is not a C function object, this fails with an exception.
528+
*func* must not be ``NULL``.
529+
530+
This function returns the function's flags on success, and ``-1`` with an
531+
exception set on failure.
532+
533+
534+
.. c:function:: int PyCFunction_GET_FLAGS(PyObject *func)
535+
536+
This is the same as :c:func:`PyCFunction_GetFlags`, but without error
537+
or type checking.
538+
539+
540+
.. c:function:: PyCFunction PyCFunction_GetFunction(PyObject *func)
541+
542+
Get the function pointer on *func* as it was passed to
543+
:c:member:`~PyMethodDef.ml_meth`.
544+
545+
If *func* is not a C function object, this fails with an exception.
546+
*func* must not be ``NULL``.
547+
548+
This function returns the function pointer on success, and ``NULL`` with an
549+
exception set on failure.
550+
551+
552+
.. c:function:: int PyCFunction_GET_FUNCTION(PyObject *func)
553+
554+
This is the same as :c:func:`PyCFunction_GetFunction`, but without error
555+
or type checking.
556+
557+
558+
.. c:function:: PyObject *PyCFunction_GetSelf(PyObject *func)
559+
560+
Get the "self" object on *func*. This is the object that would be passed
561+
to the first argument of a :c:type:`PyCFunction`. For C function objects
562+
created through a :c:type:`PyMethodDef` on a :c:type:`PyModuleDef`, this
563+
is the resulting module object.
564+
565+
If *func* is not a C function object, this fails with an exception.
566+
*func* must not be ``NULL``.
567+
568+
This function returns a :term:`borrowed reference` to the "self" object
569+
on success, and ``NULL`` with an exception set on failure.
570+
571+
572+
.. c:function:: PyObject *PyCFunction_GET_SELF(PyObject *func)
573+
574+
This is the same as :c:func:`PyCFunction_GetSelf`, but without error or
575+
type checking.
576+
577+
485578
Accessing attributes of extension types
486579
---------------------------------------
487580

Doc/library/cmdline.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ The following modules have a command-line interface.
1616
* :ref:`dis <dis-cli>`
1717
* :ref:`doctest <doctest-cli>`
1818
* :mod:`!encodings.rot_13`
19-
* :mod:`ensurepip`
19+
* :ref:`ensurepip <ensurepip-cli>`
2020
* :mod:`filecmp`
2121
* :mod:`fileinput`
2222
* :mod:`ftplib`
2323
* :ref:`gzip <gzip-cli>`
2424
* :ref:`http.server <http-server-cli>`
25-
* :mod:`!idlelib`
25+
* :ref:`idlelib <idlelib-cli>`
2626
* :ref:`inspect <inspect-module-cli>`
2727
* :ref:`json <json-commandline>`
2828
* :ref:`mimetypes <mimetypes-cli>`
29-
* :mod:`pdb`
29+
* :ref:`pdb <pdb-cli>`
3030
* :ref:`pickle <pickle-cli>`
3131
* :ref:`pickletools <pickletools-cli>`
3232
* :ref:`platform <platform-cli>`
@@ -52,8 +52,8 @@ The following modules have a command-line interface.
5252
* :mod:`turtledemo`
5353
* :ref:`unittest <unittest-command-line-interface>`
5454
* :ref:`uuid <uuid-cli>`
55-
* :mod:`venv`
56-
* :mod:`webbrowser`
55+
* :ref:`venv <venv-cli>`
56+
* :ref:`webbrowser <webbrowser-cli>`
5757
* :ref:`zipapp <zipapp-command-line-interface>`
5858
* :ref:`zipfile <zipfile-commandline>`
5959

Doc/library/ensurepip.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ when creating a virtual environment) or after explicitly uninstalling
4242

4343
.. include:: ../includes/wasm-mobile-notavail.rst
4444

45-
Command line interface
45+
.. _ensurepip-cli:
46+
47+
Command-line interface
4648
----------------------
4749

4850
.. program:: ensurepip

Doc/library/gzip.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ Example of how to GZIP compress a binary string::
283283

284284
.. _gzip-cli:
285285

286-
Command Line Interface
286+
Command-line interface
287287
----------------------
288288

289289
The :mod:`gzip` module provides a simple command line interface to compress or
@@ -296,7 +296,7 @@ Once executed the :mod:`gzip` module keeps the input file(s).
296296
Add a new command line interface with a usage.
297297
By default, when you will execute the CLI, the default compression level is 6.
298298

299-
Command line options
299+
Command-line options
300300
^^^^^^^^^^^^^^^^^^^^
301301

302302
.. option:: file

Doc/library/idle.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,9 @@ looked for in the user's home directory. Statements in this file will be
661661
executed in the Tk namespace, so this file is not useful for importing
662662
functions to be used from IDLE's Python shell.
663663

664-
Command line usage
664+
.. _idlelib-cli:
665+
666+
Command-line usage
665667
^^^^^^^^^^^^^^^^^^
666668

667669
.. program:: idle

0 commit comments

Comments
 (0)