8000 Merge branch 'main' into pymodule-add4b · python/cpython@63fa1ba · GitHub
[go: up one dir, main page]

Skip to content

Commit 63fa1ba

Browse files
Merge branch 'main' into pymodule-add4b
2 parents 8703a44 + 83ac128 commit 63fa1ba

File tree

107 files changed

+4156
-1642
lines changed

Some content is hidden

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

107 files changed

+4156
-1642
lines changed

.coveragerc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[run]
2+
branch = True
3+
4+
[report]
5+
# Regexes for lines to exclude from consideration
6+
exclude_lines =
7+
# Don't complain if non-runnable code isn't run:
8+
if 0:
9+
if __name__ == .__main__.:
10+
11+
.*# pragma: no cover
12+
.*# pragma: no branch
13+
14+
# Additions for IDLE:
15+
.*# htest #
16+
if not (_htest or _utest):
17+
if not .*_utest:
18+
if .*_htest:
19+

.github/CODEOWNERS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,9 @@ Doc/c-api/stable.rst @encukou
172172
**/*pathlib* @barneygale
173173

174174
# zipfile.Path
175-
**/*zipfile/*_path.py @jaraco
175+
**/*zipfile/_path/* @jaraco
176176

177177
# Argument Clinic
178178
/Tools/clinic/** @erlend-aasland @AlexWaygood
179179
/Lib/test/test_clinic.py @erlend-aasland @AlexWaygood
180+
Doc/howto/clinic.rst @erlend-aasland

Doc/c-api/module.rst

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -486,12 +486,29 @@ state:
486486
.. versionadded:: 3.10
487487
488488
489+
.. c:function:: int PyModule_Add(PyObject *module, const char *name, PyObject *value)
490+
491+
Similar to :c:func:`PyModule_AddObjectRef`, but "steals" a reference
492+
to *value*.
493+
It can be called with a result of function that returns a new reference
494+
without bothering to check its result or even saving it to a variable.
495+
496+
Example usage::
497+
498+
if (PyModule_Add(module, "spam", PyBytes_FromString(value)) < 0) {
499+
goto error;
500+
}
501+
502+
.. versionadded:: 3.13
503+
504+
489505
.. c:function:: int PyModule_AddObject(PyObject *module, const char *name, PyObject *value)
490506
491507
Similar to :c:func:`PyModule_AddObjectRef`, but steals a reference to
492508
*value* on success (if it returns ``0``).
493509
494-
The new :c:func:`PyModule_AddObjectRef` function is recommended, since it is
510+
The new :c:func:`PyModule_Add` or :c:func:`PyModule_AddObjectRef`
511+
functions are recommended, since it is
495512
easy to introduce reference leaks by misusing the
496513
:c:func:`PyModule_AddObject` function.
497514
@@ -501,44 +518,24 @@ state:
D7AE
501518
only decrements the reference count of *value* **on success**.
502519
503520
This means that its return value must be checked, and calling code must
504-
:c:func:`Py_DECREF` *value* manually on error.
521+
:c:func:`Py_XDECREF` *value* manually on error.
505522
506523
Example usage::
507524
508-
static int
509-
add_spam(PyObject *module, int value)
510-
{
511-
PyObject *obj = PyLong_FromLong(value);
512-
if (obj == NULL) {
513-
return -1;
514-
}
515-
if (PyModule_AddObject(module, "spam", obj) < 0) {
516-
Py_DECREF(obj);
517-
return -1;
518-
}
519-
// PyModule_AddObject() stole a reference to obj:
520-
// Py_DECREF(obj) is not needed here
521-
return 0;
522-
}
523-
524-
The example can also be written without checking explicitly if *obj* is
525-
``NULL``::
525+
PyObject *obj = PyBytes_FromString(value);
526+
if (PyModule_AddObject(module, "spam", obj) < 0) {
527+
// If 'obj' is not NULL and PyModule_AddObject() failed,
528+
// 'obj' strong reference must be deleted with Py_XDECREF().
529+
// If 'obj' is NULL, Py_XDECREF() does nothing.
530+
Py_XDECREF(obj);
531+
goto error;
532+
}
533+
// PyModule_AddObject() stole a reference to obj:
534+
// Py_XDECREF(obj) is not needed here.
526535
527-
static int
528-
add_spam(PyObject *module, int value)
529-
{
530-
PyObject *obj = PyLong_FromLong(value);
531-
if (PyModule_AddObject(module, "spam", obj) < 0) {
532-
Py_XDECREF(obj);
533-
return -1;
534-
}
535-
// PyModule_AddObject() stole a reference to obj:
536-
// Py_DECREF(obj) is not needed here
537-
return 0;
538-
}
536+
.. deprecated:: 3.13
539537
540-
Note that ``Py_XDECREF()`` should be used instead of ``Py_DECREF()`` in
541-
this case, since *obj* can be ``NULL``.
538+
:c:func:`PyModule_AddObject` is :term:`soft deprecated`.
542539
543540
544541
.. c:function:: int PyModule_AddIntConstant(PyObject *module, const char *name, long value)

Doc/data/stable_abi.dat

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Doc/faq/library.rst

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -669,41 +669,6 @@ and client-side web systems.
669669
A summary of available frameworks is maintained by Paul Boddie at
670670
https://wiki.python.org/moin/WebProgramming\ .
671671
672-
Cameron Laird maintains a useful set of pages about Python web technologies at
673-
https://web.archive.org/web/20210224183619/http://phaseit.net/claird/comp.lang.python/web_python.
674-
675-
676-
How can I mimic CGI form submission (METHOD=POST)?
677-
--------------------------------------------------
678-
679-
I would like to retrieve web pages that are the result of POSTing a form. Is
680-
there existing code that would let me do this easily?
681-
682-
Yes. Here's a simple example that uses :mod:`urllib.request`::
683-
684-
#!/usr/local/bin/python
685-
686-
import urllib.request
687-
688-
# build the query string
689-
qs = "First=Josephine&MI=Q&Last=Public"
690-
691-
# connect and send the server a path
692-
req = urllib.request.urlopen('http://www.some-server.out-there'
693-
'/cgi-bin/some-cgi-script', data=qs)
694-
with req:
695-
msg, hdrs = req.read(), req.info()
696-
697-
Note that in general for percent-encoded POST operations, query strings must be
698-
quoted using :func:`urllib.parse.urlencode`. For example, to send
699-
``name=Guy Steele, Jr.``::
700-
701-
>>> import urllib.parse
702-
>>> urllib.parse.urlencode({'name': 'Guy Steele, Jr.'})
703-
'name=Guy+Steele%2C+Jr.'
704-
705-
.. seealso:: :ref:`urllib-howto` for extensive examples.
706-
707672
708673
What module should I use to help with generating HTML?
709674
------------------------------------------------------

Doc/howto/clinic.rst

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ Argument Clinic How-To
2727
version of Argument Clinic that ships with the next version
2828
of CPython *could* be totally incompatible and break all your code.
2929

30-
The Goals Of Argument Clinic
30+
31+
The goals of Argument Clinic
3132
============================
3233

3334
Argument Clinic's primary goal
@@ -78,7 +79,7 @@ and it should be able to do many interesting and smart
7879
things with all the information you give it.
7980

8081

81-
Basic Concepts And Usage
82+
Basic concepts and usage
8283
========================
8384

8485
Argument Clinic ships with CPython; you'll find it in ``Tools/clinic/clinic.py``.
@@ -141,7 +142,7 @@ For the sake of clarity, here's the terminology we'll use with Argument Clinic:
141142
a block.)
142143

143144

144-
Converting Your First Function
145+
Converting your first function
145146
==============================
146147

147148
The best way to get a sense of how Argument Clinic works is to
@@ -558,7 +559,8 @@ Let's dive in!
558559

559560
Congratulations, you've ported your first function to work with Argument Clinic!
560561

561-
Advanced Topics
562+
563+
Advanced topics
562564
===============
563565

564566
Now that you've had some experience working with Argument Clinic, it's time
@@ -636,7 +638,8 @@ after the last argument).
636638
Currently the generated code will use :c:func:`PyArg_ParseTuple`, but this
637639
will change soon.
638640

639-
Optional Groups
641+
642+
Optional groups
640643
---------------
641644

642645
Some legacy functions have a tricky approach to parsing their arguments:
@@ -899,6 +902,7 @@ available. For each converter it'll show you all the parameters
899902it accepts, along with the default value for each parameter.
900903
Just run ``Tools/clinic/clinic.py --converters`` to see the full list.
901904

905+
902906
Py_buffer
903907
---------
904908

@@ -908,7 +912,6 @@ you *must* not call :c:func:`PyBuffer_Release` on the provided buffer.
908912
Argument Clinic generates code that does it for you (in the parsing function).
909913

910914

911-
912915
Advanced converters
913916
-------------------
914917

@@ -975,6 +978,7 @@ value called ``NULL`` for just this reason: from Python's perspective it
975978
behaves like a default value of ``None``, but the C variable is initialized
976979
with ``NULL``.
977980

981+
978982
Expressions specified as default values
979983
---------------------------------------
980984

@@ -1032,7 +1036,6 @@ you're not permitted to use:
10321036
* Tuple/list/set/dict literals.
10331037

10341038

1035-
10361039
Using a return converter
10371040
------------------------
10381041

@@ -1146,6 +1149,7 @@ then modifying it. Cloning is an all-or nothing proposition.
11461149
Also, the function you are cloning from must have been previously defined
11471150
in the current file.
11481151

1152+
11491153
Calling Python code
11501154
-------------------
11511155

@@ -1380,6 +1384,7 @@ handle initialization and cleanup.
13801384
You can see more examples of custom converters in the CPython
13811385
source tree; grep the C files for the string ``CConverter``.
13821386

1387+
13831388
Writing a custom return converter
13841389
---------------------------------
13851390

@@ -1394,8 +1399,9 @@ write your own return converter, please read ``Tools/clinic/clinic.py``,
13941399
specifically the implementation of ``CReturnConverter`` and
13951400
all its subclasses.
13961401

1402+
13971403
METH_O and METH_NOARGS
1398-
----------------------------------------------
1404+
----------------------
13991405

14001406
To convert a function using ``METH_O``, make sure the function's
14011407
single argument is using the ``object`` converter, and mark the
@@ -1415,8 +1421,9 @@ any arguments.
14151421
You can still use a self converter, a return converter, and specify
14161422
a ``type`` argument to the object converter for ``METH_O``.
14171423

1424+
14181425
tp_new and tp_init functions
1419-
----------------------------------------------
1426+
----------------------------
14201427

14211428
You can convert ``tp_new`` and ``tp_init`` functions. Just name
14221429
them ``__new__`` or ``__init__`` as appropriate. Notes:
@@ -1437,6 +1444,7 @@ them ``__new__`` or ``__init__`` as appropriate. Notes:
14371444
(If your function doesn't support keywords, the parsing function
14381445
generated will throw an exception if it receives any.)
14391446

1447+
14401448
Changing and redirecting Clinic's output
14411449
----------------------------------------
14421450

@@ -1721,7 +1729,7 @@ the file was not modified by hand before it gets overwritten.
17211729

17221730

17231731
The #ifdef trick
1724-
----------------------------------------------
1732+
----------------
17251733

17261734
If you're converting a function that isn't available on all platforms,
17271735
there's a trick you can use to make life a little easier. The existing
@@ -1801,7 +1809,6 @@ Argument Clinic added to your file (it'll be at the very bottom), then
18011809
move it above the ``PyMethodDef`` structure where that macro is used.
18021810

18031811

1804-
18051812
Using Argument Clinic in Python files
18061813
-------------------------------------
18071814

Doc/includes/email-alternative.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99
# Create the base text message.
1010
msg = EmailMessage()
11-
msg['Subject'] = "Ayons asperges pour le déjeuner"
11+
msg['Subject'] = "Pourquoi pas des asperges pour ce midi ?"
1212
msg['From'] = Address("Pepé Le Pew", "pepe", "example.com")
1313
msg['To'] = (Address("Penelope Pussycat", "penelope", "example.com"),
1414
Address("Fabrette Pussycat", "fabrette", "example.com"))
1515
msg.set_content("""\
1616
Salut!
1717
18-
Cela ressemble à un excellent recipie[1] déjeuner.
18+
Cette recette [1] sera sûrement un très bon repas.
1919
2020
[1] http://www.yummly.com/recipe/Roasted-Asparagus-Epicurious-203718
2121
@@ -31,10 +31,10 @@
3131
<head></head>
3232
<body>
3333
<p>Salut!</p>
34-
<p>Cela ressemble à un excellent
34+
<p>Cette
3535
<a href="http://www.yummly.com/recipe/Roasted-Asparagus-Epicurious-203718">
36-
recipie
37-
</a> déjeuner.
36+
recette
37+
</a> sera sûrement un très bon repas.
3838
</p>
3939
<img src="cid:{asparagus_cid}" />
4040
</body>

Doc/library/devmode.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ setting the :envvar:`PYTHONDEVMODE` environment variable to ``1``.
1616
See also :ref:`Python debug build <debug-build>`.
1717

1818
Effects of the Python Development Mode
19-
======================================
19+
--------------------------------------
2020

2121
Enabling the Python Development Mode is similar to the following command, but
2222
with additional effects described below::
@@ -107,7 +107,7 @@ value can be read from :data:`sys.flags.dev_mode <sys.flags>`.
107107

108108

109109
ResourceWarning Example
110-
=======================
110+
-----------------------
111111

112112
Example of a script counting the number of lines of the text file specified in
113113
the command line::
@@ -171,7 +171,7 @@ application more deterministic and more reliable.
171171

172172

173173
Bad file descriptor error example
174-
=================================
174+
---------------------------------
175175

176176
Script displaying the first line of itself::
177177

@@ -198,7 +198,7 @@ descriptor" error when finalizing the file object:
198198

199199
.. code-block:: shell-session
200200
201-
$ python script.py
201+
$ python -X dev script.py
202202
import os
203203
script.py:10: ResourceWarning: unclosed file <_io.TextIOWrapper name='script.py' mode='r' encoding='UTF-8'>
204204
main()

Doc/library/email.examples.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ Up to the prompt, the output from the above is:
5555
5656
To: Penelope Pussycat <penelope@example.com>, Fabrette Pussycat <fabrette@example.com>
5757
From: Pepé Le Pew <pepe@example.com>
58-
Subject: Ayons asperges pour le déjeuner
58+
Subject: Pourquoi pas des asperges pour ce midi ?
5959
6060
Salut!
6161
62-
Cela ressemble à un excellent recipie[1] déjeuner.
62+
Cette recette [1] sera sûrement un très bon repas.
6363
6464
6565
.. rubric:: Footnotes

0 commit comments

Comments
 (0)
0