Skip to content

Commit e7c639f

Browse files
Merge branch 'main' into getopt-optional
2 parents 1836f8f + fe5a6ab commit e7c639f

File tree

12 files changed

+56
-83
lines changed

12 files changed

+56
-83
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,6 @@ Pending removal in Python 3.14
103103
if :ref:`named placeholders <sqlite3-placeholders>` are used and
104104
*parameters* is a sequence instead of a :class:`dict`.
105105

106-
* date and datetime adapter, date and timestamp converter:
107-
see the :mod:`sqlite3` documentation for suggested replacement recipes.
108-
109106
* :class:`types.CodeType`: Accessing :attr:`~codeobject.co_lnotab` was
110107
deprecated in :pep:`626`
111108
since 3.10 and was planned to be removed in 3.12,

Doc/library/asyncio-eventloop.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,8 @@ an event loop:
5959
instead of using these lower level functions to manually create and close an
6060
event loop.
6161

62-
.. deprecated:: 3.12
63-
Deprecation warning is emitted if there is no current event loop.
64-
In some future Python release this will become an error.
62+
.. versionchanged:: 3.14
63+
Raises a :exc:`RuntimeError` if there is no current event loop.
6564

6665
.. function:: set_event_loop(loop)
6766

Doc/library/asyncio-policy.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,9 @@ asyncio ships with the following built-in policies:
9797

9898
On Windows, :class:`ProactorEventLoop` is now used by default.
9999

100-
.. deprecated:: 3.12
101-
The :meth:`get_event_loop` method of the default asyncio policy now emits
102-
a :exc:`DeprecationWarning` if there is no current event loop set and it
103-
decides to create one.
104-
In some future Python release this will become an error.
100+
.. versionchanged:: 3.14
101+
The :meth:`get_event_loop` method of the default asyncio policy now
102+
raises a :exc:`RuntimeError` if there is no set event loop.
105103

106104

107105
.. class:: WindowsSelectorEventLoopPolicy

Doc/library/cmath.rst

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,19 +221,21 @@ Classification functions
221221
``False`` otherwise.
222222

223223
Whether or not two values are considered close is determined according to
224-
given absolute and relative tolerances.
224+
given absolute and relative tolerances. If no errors occur, the result will
225+
be: ``abs(a-b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)``.
225226

226227
*rel_tol* is the relative tolerance -- it is the maximum allowed difference
227228
between *a* and *b*, relative to the larger absolute value of *a* or *b*.
228229
For example, to set a tolerance of 5%, pass ``rel_tol=0.05``. The default
229230
tolerance is ``1e-09``, which assures that the two values are the same
230-
within about 9 decimal digits. *rel_tol* must be greater than zero.
231-
232-
*abs_tol* is the minimum absolute tolerance -- useful for comparisons near
233-
zero. *abs_tol* must be at least zero.
234-
235-
If no errors occur, the result will be:
236-
``abs(a-b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)``.
231+
within about 9 decimal digits. *rel_tol* must be nonnegative and less
232+
than ``1.0``.
233+
234+
*abs_tol* is the absolute tolerance; it defaults to ``0.0`` and it must be
235+
nonnegative. When comparing ``x`` to ``0.0``, ``isclose(x, 0)`` is computed
236+
as ``abs(x) <= rel_tol * abs(x)``, which is ``False`` for any ``x`` and
237+
rel_tol less than ``1.0``. So add an appropriate positive abs_tol argument
238+
to the call.
237239

238240
The IEEE 754 special values of ``NaN``, ``inf``, and ``-inf`` will be
239241
handled according to IEEE rules. Specifically, ``NaN`` is not considered

Doc/library/getopt.rst

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ exception:
103103

104104
An example using only Unix style options:
105105

106+
.. doctest::
107+
106108
>>> import getopt
107109
>>> args = '-a -b -cfoo -d bar a1 a2'.split()
108110
>>> args
@@ -115,6 +117,8 @@ An example using only Unix style options:
115117

116118
Using long option names is equally easy:
117119

120+
.. doctest::
121+
118122
>>> s = '--condition=foo --testing --output-file abc.def -x a1 a2'
119123
>>> args = s.split()
120124
>>> args
@@ -128,6 +132,8 @@ Using long option names is equally easy:
128132

129133
Optional arguments should be specified explicitly:
130134

135+
.. doctest::
136+
131137
>>> s = '-Con -C --color=off --color a1 a2'
132138
>>> args = s.split()
133139
>>> args
@@ -138,7 +144,9 @@ Optional arguments should be specified explicitly:
138144
>>> args
139145
['a1', 'a2']
140146

141-
In a script, typical usage is something like this::
147+
In a script, typical usage is something like this:
148+
149+
.. testcode::
142150

143151
import getopt, sys
144152

@@ -168,7 +176,9 @@ In a script, typical usage is something like this::
168176
main()
169177

170178
Note that an equivalent command line interface could be produced with less code
171-
and more informative help and error messages by using the :mod:`argparse` module::
179+
and more informative help and error messages by using the :mod:`argparse` module:
180+
181+
.. testcode::
172182

173183
import argparse
174184

Doc/library/math.rst

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -244,19 +244,21 @@ Number-theoretic and representation functions
244244
``False`` otherwise.
245245

246246
Whether or not two values are considered close is determined according to
247-
given absolute and relative tolerances.
247+
given absolute and relative tolerances. If no errors occur, the result will
248+
be: ``abs(a-b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)``.
248249

249250
*rel_tol* is the relative tolerance -- it is the maximum allowed difference
250251
between *a* and *b*, relative to the larger absolute value of *a* or *b*.
251252
For example, to set a tolerance of 5%, pass ``rel_tol=0.05``. The default
252253
tolerance is ``1e-09``, which assures that the two values are the same
253-
within about 9 decimal digits. *rel_tol* must be greater than zero.
254-
255-
*abs_tol* is the minimum absolute tolerance -- useful for comparisons near
256-
zero. *abs_tol* must be at least zero.
257-
258-
If no errors occur, the result will be:
259-
``abs(a-b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)``.
254+
within about 9 decimal digits. *rel_tol* must be nonnegative and less
255+
than ``1.0``.
256+
257+
*abs_tol* is the absolute tolerance; it defaults to ``0.0`` and it must be
258+
nonnegative. When comparing ``x`` to ``0.0``, ``isclose(x, 0)`` is computed
259+
as ``abs(x) <= rel_tol * abs(x)``, which is ``False`` for any ``x`` and
260+
rel_tol less than ``1.0``. So add an appropriate positive abs_tol argument
261+
to the call.
260262

261263
The IEEE 754 special values of ``NaN``, ``inf``, and ``-inf`` will be
262264
handled according to IEEE rules. Specifically, ``NaN`` is not considered

Doc/whatsnew/3.14.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,11 @@ asyncio
581581

582582
(Contributed by Kumar Aditya in :gh:`120804`.)
583583

584+
* Removed implicit creation of event loop by :func:`asyncio.get_event_loop`.
585+
It now raises a :exc:`RuntimeError` if there is no current event loop.
586+
(Contributed by Kumar Aditya in :gh:`126353`.)
587+
588+
584589
collections.abc
585590
---------------
586591

Lib/asyncio/events.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,6 @@ class BaseDefaultEventLoopPolicy(AbstractEventLoopPolicy):
668668

669669
class _Local(threading.local):
670670
_loop = None
671-
_set_called = False
672671

673672
def __init__(self):
674673
self._local = self._Local()
@@ -678,28 +677,6 @@ def get_event_loop(self):
678677
679678
Returns an instance of EventLoop or raises an exception.
680679
"""
681-
if (self._local._loop is None and
682-
not self._local._set_called and
683-
threading.current_thread() is threading.main_thread()):
684-
stacklevel = 2
685-
try:
686-
f = sys._getframe(1)
687-
except AttributeError:
688-
pass
689-
else:
690-
# Move up the call stack so that the warning is attached
691-
# to the line outside asyncio itself.
692-
while f:
693-
module = f.f_globals.get('__name__')
694-
if not (module == 'asyncio' or module.startswith('asyncio.')):
695-
break
696-
f = f.f_back
697-
stacklevel += 1
698-
import warnings
699-
warnings.warn('There is no current event loop',
700-
DeprecationWarning, stacklevel=stacklevel)
701-
self.set_event_loop(self.new_event_loop())
702-
703680
if self._local._loop is None:
704681
raise RuntimeError('There is no current event loop in thread %r.'
705682
% threading.current_thread().name)
@@ -708,7 +685,6 @@ def get_event_loop(self):
708685

709686
def set_event_loop(self, loop):
710687
"""Set the event loop."""
711-
self._local._set_called = True
712688
if loop is not None and not isinstance(loop, AbstractEventLoop):
713689
raise TypeError(f"loop must be an instance of AbstractEventLoop or None, not '{type(loop).__name__}'")
714690
self._local._loop = loop

Lib/test/test_asyncio/test_events.py

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2704,33 +2704,22 @@ def test_event_loop_policy(self):
27042704
def test_get_event_loop(self):
27052705
policy = asyncio.DefaultEventLoopPolicy()
27062706
self.assertIsNone(policy._local._loop)
2707-
with self.assertWarns(DeprecationWarning) as cm:
2708-
loop = policy.get_event_loop()
2709-
self.assertEqual(cm.filename, __file__)
2710-
self.assertIsInstance(loop, asyncio.AbstractEventLoop)
27112707

2712-
self.assertIs(policy._local._loop, loop)
2713-
self.assertIs(loop, policy.get_event_loop())
2714-
loop.close()
2708+
with self.assertRaises(RuntimeError):
2709+
loop = policy.get_event_loop()
2710+
self.assertIsNone(policy._local._loop)
27152711

2716-
def test_get_event_loop_calls_set_event_loop(self):
2712+
def test_get_event_loop_does_not_call_set_event_loop(self):
27172713
policy = asyncio.DefaultEventLoopPolicy()
27182714

27192715
with mock.patch.object(
27202716
policy, "set_event_loop",
27212717
wraps=policy.set_event_loop) as m_set_event_loop:
27222718

2723-
with self.assertWarns(DeprecationWarning) as cm:
2719+
with self.assertRaises(RuntimeError):
27242720
loop = policy.get_event_loop()
2725-
self.addCleanup(loop.close)
2726-
self.assertEqual(cm.filename, __file__)
27272721

2728-
# policy._local._loop must be set through .set_event_loop()
2729-
# (the unix DefaultEventLoopPolicy needs this call to attach
2730-
# the child watcher correctly)
2731-
m_set_event_loop.assert_called_with(loop)
2732-
2733-
loop.close()
2722+
m_set_event_loop.assert_not_called()
27342723

27352724
def test_get_event_loop_after_set_none(self):
27362725
policy = asyncio.DefaultEventLoopPolicy()
@@ -2912,17 +2901,12 @@ def test_get_event_loop_returns_running_loop2(self):
29122901
loop = asyncio.new_event_loop()
29132902
self.addCleanup(loop.close)
29142903

2915-
with self.assertWarns(DeprecationWarning) as cm:
2916-
loop2 = asyncio.get_event_loop()
2917-
self.addCleanup(loop2.close)
2918-
self.assertEqual(cm.filename, __file__)
2919-
asyncio.set_event_loop(None)
29202904
with self.assertRaisesRegex(RuntimeError, 'no current'):
29212905
asyncio.get_event_loop()
29222906

2923-
with self.assertRaisesRegex(RuntimeError, 'no running'):
2924-
asyncio.get_running_loop()
2925-
self.assertIs(asyncio._get_running_loop(), None)
2907+
asyncio.set_event_loop(None)
2908+
with self.assertRaisesRegex(RuntimeError, 'no current'):
2909+
asyncio.get_event_loop()
29262910

29272911
async def func():
29282912
self.assertIs(asyncio.get_event_loop(), loop)

Lib/test/test_asyncio/test_unix_events.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,8 +1195,7 @@ async def test_fork_not_share_event_loop(self):
11951195
if pid == 0:
11961196
# child
11971197
try:
1198-
with self.assertWarns(DeprecationWarning):
1199-
loop = asyncio.get_event_loop_policy().get_event_loop()
1198+
loop = asyncio.get_event_loop()
12001199
os.write(w, b'LOOP:' + str(id(loop)).encode())
12011200
except RuntimeError:
12021201
os.write(w, b'NO LOOP')
@@ -1207,8 +1206,7 @@ async def test_fork_not_share_event_loop(self):
12071206
else:
12081207
# parent
12091208
result = os.read(r, 100)
1210-
self.assertEqual(result[:5], b'LOOP:', result)
1211-
self.assertNotEqual(int(result[5:]), id(loop))
1209+
self.assertEqual(result, b'NO LOOP')
12121210
wait_process(pid, exitcode=0)
12131211

12141212
@hashlib_helper.requires_hashdigest('md5')

0 commit comments

Comments
 (0)