Skip to content

Commit 4db35b0

Browse files
authored
Merge branch '3.13' into backport-3402e13-3.13
2 parents ef05490 + 1b2cfb7 commit 4db35b0

22 files changed

+310
-47
lines changed

Doc/c-api/function.rst

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,13 @@ There are a few functions specific to Python functions.
145145
146146
.. c:type:: PyFunction_WatchEvent
147147
148-
Enumeration of possible function watcher events:
149-
- ``PyFunction_EVENT_CREATE``
150-
- ``PyFunction_EVENT_DESTROY``
151-
- ``PyFunction_EVENT_MODIFY_CODE``
152-
- ``PyFunction_EVENT_MODIFY_DEFAULTS``
153-
- ``PyFunction_EVENT_MODIFY_KWDEFAULTS``
148+
Enumeration of possible function watcher events:
149+
150+
- ``PyFunction_EVENT_CREATE``
151+
- ``PyFunction_EVENT_DESTROY``
152+
- ``PyFunction_EVENT_MODIFY_CODE``
153+
- ``PyFunction_EVENT_MODIFY_DEFAULTS``
154+
- ``PyFunction_EVENT_MODIFY_KWDEFAULTS``
154155
155156
.. versionadded:: 3.12
156157

Doc/glossary.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -926,11 +926,16 @@ Glossary
926926
modules, respectively.
927927

928928
namespace package
929-
A :pep:`420` :term:`package` which serves only as a container for
930-
subpackages. Namespace packages may have no physical representation,
929+
A :term:`package` which serves only as a container for subpackages.
930+
Namespace packages may have no physical representation,
931931
and specifically are not like a :term:`regular package` because they
932932
have no ``__init__.py`` file.
933933

934+
Namespace packages allow several individually installable packages to have a common parent package.
935+
Otherwise, it is recommended to use a :term:`regular package`.
936+
937+
For more information, see :pep:`420` and :ref:`reference-namespace-package`.
938+
934939
See also :term:`module`.
935940

936941
nested scope

Doc/library/unittest.mock.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1984,7 +1984,7 @@ Imagine we have a project that we want to test with the following structure::
19841984

19851985
Now we want to test ``some_function`` but we want to mock out ``SomeClass`` using
19861986
:func:`patch`. The problem is that when we import module b, which we will have to
1987-
do then it imports ``SomeClass`` from module a. If we use :func:`patch` to mock out
1987+
do when it imports ``SomeClass`` from module a. If we use :func:`patch` to mock out
19881988
``a.SomeClass`` then it will have no effect on our test; module b already has a
19891989
reference to the *real* ``SomeClass`` and it looks like our patching had no
19901990
effect.

Doc/reference/import.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ Importing ``parent.one`` will implicitly execute ``parent/__init__.py`` and
123123
``parent/three/__init__.py`` respectively.
124124

125125

126+
.. _reference-namespace-package:
127+
126128
Namespace packages
127129
------------------
128130

Lib/asyncio/base_events.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,8 @@ def _run_forever_cleanup(self):
671671

672672
def run_forever(self):
673673
"""Run until stop() is called."""
674+
self._run_forever_setup()
674675
try:
675-
self._run_forever_setup()
676676
while True:
677677
self._run_once()
678678
if self._stopping:

Lib/functools.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -958,9 +958,6 @@ def __init__(self, func):
958958
self.dispatcher = singledispatch(func)
959959
self.func = func
960960

961-
import weakref # see comment in singledispatch function
962-
self._method_cache = weakref.WeakKeyDictionary()
963-
964961
def register(self, cls, method=None):
965962
"""generic_method.register(cls, func) -> func
966963
@@ -969,16 +966,6 @@ def register(self, cls, method=None):
969966
return self.dispatcher.register(cls, func=method)
970967

971968
def __get__(self, obj, cls=None):
972-
if self._method_cache is not None:
973-
try:
974-
_method = self._method_cache[obj]
975-
except TypeError:
976-
self._method_cache = None
977-
except KeyError:
978-
pass
979-
else:
980-
return _method
981-
982969
dispatch = self.dispatcher.dispatch
983970
funcname = getattr(self.func, '__name__', 'singledispatchmethod method')
984971
def _method(*args, **kwargs):
@@ -991,9 +978,6 @@ def _method(*args, **kwargs):
991978
_method.register = self.register
992979
update_wrapper(_method, self.func)
993980

994-
if self._method_cache is not None:
995-
self._method_cache[obj] = _method
996-
997981
return _method
998982

999983
@property

Lib/subprocess.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@
4343
import builtins
4444
import errno
4545
import io
46+
import locale
4647
import os
4748
import time
49+
import signal
4850
import sys
4951
import threading
5052
import warnings
@@ -142,8 +144,6 @@ def __init__(self, returncode, cmd, output=None, stderr=None):
142144

143145
def __str__(self):
144146
if self.returncode and self.returncode < 0:
145-
# Lazy import to improve module import time
146-
import signal
147147
try:
148148
return "Command '%s' died with %r." % (
149149
self.cmd, signal.Signals(-self.returncode))
@@ -381,8 +381,6 @@ def _text_encoding():
381381
if sys.flags.utf8_mode:
382382
return "utf-8"
383383
else:
384-
# Lazy import to improve module import time
385-
import locale
386384
return locale.getencoding()
387385

388386

@@ -1667,9 +1665,6 @@ def send_signal(self, sig):
16671665
# Don't signal a process that we know has already died.
16681666
if self.returncode is not None:
16691667
return
1670-
1671-
# Lazy import to improve module import time
1672-
import signal
16731668
if sig == signal.SIGTERM:
16741669
self.terminate()
16751670
elif sig == signal.CTRL_C_EVENT:
@@ -1771,9 +1766,6 @@ def _posix_spawn(self, args, executable, env, restore_signals, close_fds,
17711766
"""Execute program using os.posix_spawn()."""
17721767
kwargs = {}
17731768
if restore_signals:
1774-
# Lazy import to improve module import time
1775-
import signal
1776-
17771769
# See _Py_RestoreSignals() in Python/pylifecycle.c
17781770
sigset = []
17791771
for signame in ('SIGPIPE', 'SIGXFZ', 'SIGXFSZ'):
@@ -2223,13 +2215,9 @@ def send_signal(self, sig):
22232215
def terminate(self):
22242216
"""Terminate the process with SIGTERM
22252217
"""
2226-
# Lazy import to improve module import time
2227-
import signal
22282218
self.send_signal(signal.SIGTERM)
22292219

22302220
def kill(self):
22312221
"""Kill the process with SIGKILL
22322222
"""
2233-
# Lazy import to improve module import time
2234-
import signal
22352223
self.send_signal(signal.SIGKILL)

Lib/test/test_asyncio/test_events.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2889,6 +2889,22 @@ async def main():
28892889
self.loop.run_until_complete(main()),
28902890
'hello')
28912891

2892+
def test_get_running_loop_already_running(self):
2893+
async def main():
2894+
running_loop = asyncio.get_running_loop()
2895+
loop = asyncio.new_event_loop()
2896+
try:
2897+
loop.run_forever()
2898+
except RuntimeError:
2899+
pass
2900+
else:
2901+
self.fail("RuntimeError not raised")
2902+
2903+
self.assertIs(asyncio.get_running_loop(), running_loop)
2904+
2905+
self.loop.run_until_complete(main())
2906+
2907+
28922908
def test_get_event_loop_returns_running_loop(self):
28932909
class TestError(Exception):
28942910
pass

Lib/test/test_capi/test_number.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,9 @@ def test_misc_multiply(self):
205205
self.assertRaises(MemoryError, inplacemultiply, [1, 2], PY_SSIZE_T_MAX//2 + 1)
206206

207207
def test_misc_power(self):
208-
# PyNumber_Power()
208+
# PyNumber_Power(), PyNumber_InPlacePower()
209209
power = _testcapi.number_power
210+
inplacepower = _testcapi.number_inplacepower
210211

211212
class HasPow(WithDunder):
212213
methname = '__pow__'
@@ -216,6 +217,39 @@ class HasPow(WithDunder):
216217
self.assertRaises(TypeError, power, 4, 11, 1.25)
217218
self.assertRaises(TypeError, power, 4, 11, HasPow.with_val(NotImplemented))
218219
self.assertRaises(TypeError, power, 4, 11, object())
220+
self.assertEqual(inplacepower(4, 11, 5), pow(4, 11, 5))
221+
self.assertRaises(TypeError, inplacepower, 4, 11, 1.25)
222+
self.assertRaises(TypeError, inplacepower, 4, 11, object())
223+
224+
class X:
225+
def __pow__(*args):
226+
return args
227+
228+
x = X()
229+
self.assertEqual(power(x, 11), (x, 11))
230+
self.assertEqual(inplacepower(x, 11), (x, 11))
231+
self.assertEqual(power(x, 11, 5), (x, 11, 5))
232+
self.assertEqual(inplacepower(x, 11, 5), (x, 11, 5))
233+
234+
class X:
235+
def __rpow__(*args):
236+
return args
237+
238+
x = X()
239+
self.assertEqual(power(4, x), (x, 4))
240+
self.assertEqual(inplacepower(4, x), (x, 4))
241+
# XXX: Three-arg power doesn't use __rpow__.
242+
self.assertRaises(TypeError, power, 4, x, 5)
243+
self.assertRaises(TypeError, inplacepower, 4, x, 5)
244+
245+
class X:
246+
def __ipow__(*args):
247+
return args
248+
249+
x = X()
250+
self.assertEqual(inplacepower(x, 11), (x, 11))
251+
# XXX: In-place power doesn't pass the third arg to __ipow__.
252+
self.assertEqual(inplacepower(x, 11, 5), (x, 11))
219253

220254
@cpython_only
221255
def test_rshift_print(self):

Lib/test/test_functools.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,16 @@ def fib(n):
13391339
self.module._CacheInfo(hits=0, misses=0, maxsize=None, currsize=0))
13401340

13411341

1342+
class TestCachePy(TestCache, unittest.TestCase):
1343+
module = py_functools
1344+
1345+
1346+
@unittest.skipUnless(c_functools, 'requires the C _functools module')
1347+
class TestCacheC(TestCache, unittest.TestCase):
1348+
if c_functools:
1349+
module = c_functools
1350+
1351+
13421352
class TestLRU:
13431353

13441354
def test_lru(self):

0 commit comments

Comments
 (0)