Skip to content

Commit 51b236c

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents 82379f1 + d711a5e commit 51b236c

File tree

9 files changed

+78
-23
lines changed

9 files changed

+78
-23
lines changed

Doc/about.rst

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
=====================
2-
About these documents
3-
=====================
1+
========================
2+
About this documentation
3+
========================
44

55

6-
These documents are generated from `reStructuredText`_ sources by `Sphinx`_, a
7-
document processor specifically written for the Python documentation.
6+
Python's documentation is generated from `reStructuredText`_ sources
7+
using `Sphinx`_, a documentation generator originally created for Python
8+
and now maintained as an independent project.
89

910
.. _reStructuredText: https://docutils.sourceforge.io/rst.html
1011
.. _Sphinx: https://www.sphinx-doc.org/
@@ -20,14 +21,14 @@ volunteers are always welcome!
2021
Many thanks go to:
2122

2223
* Fred L. Drake, Jr., the creator of the original Python documentation toolset
23-
and writer of much of the content;
24+
and author of much of the content;
2425
* the `Docutils <https://docutils.sourceforge.io/>`_ project for creating
2526
reStructuredText and the Docutils suite;
2627
* Fredrik Lundh for his Alternative Python Reference project from which Sphinx
2728
got many good ideas.
2829

2930

30-
Contributors to the Python Documentation
31+
Contributors to the Python documentation
3132
----------------------------------------
3233

3334
Many people have contributed to the Python language, the Python standard

Doc/deprecations/pending-removal-in-3.16.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,8 @@ Pending removal in Python 3.16
7979

8080
* The undocumented and unused :attr:`!TarFile.tarfile` attribute
8181
has been deprecated since Python 3.13.
82+
83+
* :mod:`functools`:
84+
85+
* Calling the Python implementation of :func:`functools.reduce` with *function*
86+
or *sequence* as keyword arguments has been deprecated since Python 3.14.

Doc/whatsnew/3.14.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,11 @@ Deprecated
744744
as a single positional argument.
745745
(Contributed by Serhiy Storchaka in :gh:`109218`.)
746746

747+
* :mod:`functools`:
748+
Calling the Python implementation of :func:`functools.reduce` with *function*
749+
or *sequence* as keyword arguments is now deprecated.
750+
(Contributed by Kirill Podoprigora in :gh:`121676`.)
751+
747752
* :mod:`os`:
748753
:term:`Soft deprecate <soft deprecated>` :func:`os.popen` and
749754
:func:`os.spawn* <os.spawnl>` functions. They should no longer be used to

Lib/functools.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,6 @@ def reduce(function, sequence, initial=_initial_missing):
264264

265265
return value
266266

267-
try:
268-
from _functools import reduce
269-
except ImportError:
270-
pass
271-
272267

273268
################################################################################
274269
### partial() argument application
@@ -1124,3 +1119,31 @@ def __get__(self, instance, owner=None):
11241119
return val
11251120

11261121
__class_getitem__ = classmethod(GenericAlias)
1122+
1123+
def _warn_python_reduce_kwargs(py_reduce):
1124+
@wraps(py_reduce)
1125+
def wrapper(*args, **kwargs):
1126+
if 'function' in kwargs or 'sequence' in kwargs:
1127+
import os
1128+
import warnings
1129+
warnings.warn(
1130+
'Calling functools.reduce with keyword arguments '
1131+
'"function" or "sequence" '
1132+
'is deprecated in Python 3.14 and will be '
1133+
'forbidden in Python 3.16.',
1134+
DeprecationWarning,
1135+
skip_file_prefixes=(os.path.dirname(__file__),))
1136+
return py_reduce(*args, **kwargs)
1137+
return wrapper
1138+
1139+
reduce = _warn_python_reduce_kwargs(reduce)
1140+
del _warn_python_reduce_kwargs
1141+
1142+
# The import of the C accelerated version of reduce() has been moved
1143+
# here due to gh-121676. In Python 3.16, _warn_python_reduce_kwargs()
1144+
# should be removed and the import block should be moved back right
1145+
# after the definition of reduce().
1146+
try:
1147+
from _functools import reduce
1148+
except ImportError:
1149+
pass

Lib/test/test_functools.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,12 @@ class TestReduceC(TestReduce, unittest.TestCase):
10451045
class TestReducePy(TestReduce, unittest.TestCase):
10461046
reduce = staticmethod(py_functools.reduce)
10471047

1048+
def test_reduce_with_kwargs(self):
1049+
with self.assertWarns(DeprecationWarning):
1050+
self.reduce(function=lambda x, y: x + y, sequence=[1, 2, 3, 4, 5], initial=1)
1051+
with self.assertWarns(DeprecationWarning):
1052+
self.reduce(lambda x, y: x + y, sequence=[1, 2, 3, 4, 5], initial=1)
1053+
10481054

10491055
class TestCmpToKey:
10501056

Lib/test/test_socket.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7075,6 +7075,26 @@ def close_fds(fds):
70757075
self.assertEqual(data, str(index).encode())
70767076

70777077

7078+
class FreeThreadingTests(unittest.TestCase):
7079+
7080+
def test_close_detach_race(self):
7081+
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
7082+
7083+
def close():
7084+
for _ in range(1000):
7085+
s.close()
7086+
7087+
def detach():
7088+
for _ in range(1000):
7089+
s.detach()
7090+
7091+
t1 = threading.Thread(target=close)
7092+
t2 = threading.Thread(target=detach)
7093+
7094+
with threading_helper.start_threads([t1, t2]):
7095+
pass
7096+
7097+
70787098
def setUpModule():
70797099
thread_info = threading_helper.threading_setup()
70807100
unittest.addModuleCleanup(threading_helper.threading_cleanup, *thread_info)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Deprecate calling the Python implementation of :meth:`functools.reduce`
2+
with a ``function`` or ``sequence`` as a :term:`keyword argument`.
3+
This will be forbidden in Python 3.16 in order to match the C implementation.

Modules/clinic/socketmodule.c.h

Lines changed: 2 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/socketmodule.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3386,7 +3386,6 @@ sockets the address is a tuple (ifname, proto [,pkttype [,hatype [,addr]]])");
33863386
will surely fail. */
33873387

33883388
/*[clinic input]
3389-
@critical_section
33903389
_socket.socket.close
33913390
self as s: self(type="PySocketSockObject *")
33923391
@@ -3397,7 +3396,7 @@ Close the socket. It cannot be used after this call.
33973396

33983397
static PyObject *
33993398
_socket_socket_close_impl(PySocketSockObject *s)
3400-
/*[clinic end generated code: output=038b2418e07f6f6c input=9839a261e05bcb97]*/
3399+
/*[clinic end generated code: output=038b2418e07f6f6c input=dc487e470e55a83c]*/
34013400
{
34023401
SOCKET_T fd;
34033402
int res;

0 commit comments

Comments
 (0)