Skip to content

Commit 12d0099

Browse files
author
Autobuild bot on TravisCI
committed
Merge remote-tracking branch 'upstream/3.10' into catalog-3.10 by Autobuild bot on TravisCI
2 parents d36f460 + d1c0e44 commit 12d0099

File tree

8 files changed

+59
-35
lines changed

8 files changed

+59
-35
lines changed

Doc/library/asyncio-eventloop.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ Scheduling callbacks
216216
A thread-safe variant of :meth:`call_soon`. Must be used to
217217
schedule callbacks *from another thread*.
218218

219+
Raises :exc:`RuntimeError` if called on a loop that's been closed.
220+
This can happen on a secondary thread when the main application is
221+
shutting down.
222+
219223
See the :ref:`concurrency and multithreading <asyncio-multithreading>`
220224
section of the documentation.
221225

Doc/tutorial/introduction.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -269,14 +269,6 @@ to obtain individual characters, *slicing* allows you to obtain substring::
269269
>>> word[2:5] # characters from position 2 (included) to 5 (excluded)
270270
'tho'
271271

272-
Note how the start is always included, and the end always excluded. This
273-
makes sure that ``s[:i] + s[i:]`` is always equal to ``s``::
274-
275-
>>> word[:2] + word[2:]
276-
'Python'
277-
>>> word[:4] + word[4:]
278-
'Python'
279-
280272
Slice indices have useful defaults; an omitted first index defaults to zero, an
281273
omitted second index defaults to the size of the string being sliced. ::
282274

@@ -287,6 +279,14 @@ omitted second index defaults to the size of the string being sliced. ::
287279
>>> word[-2:] # characters from the second-last (included) to the end
288280
'on'
289281

282+
Note how the start is always included, and the end always excluded. This
283+
makes sure that ``s[:i] + s[i:]`` is always equal to ``s``::
284+
285+
>>> word[:2] + word[2:]
286+
'Python'
287+
>>> word[:4] + word[4:]
288+
'Python'
289+
290290
One way to remember how slices work is to think of the indices as pointing
291291
*between* characters, with the left edge of the first character numbered 0.
292292
Then the right edge of the last character of a string of *n* characters has

Lib/subprocess.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,8 +660,9 @@ def _use_posix_spawn():
660660
# os.posix_spawn() is not available
661661
return False
662662

663-
if sys.platform == 'darwin':
664-
# posix_spawn() is a syscall on macOS and properly reports errors
663+
if sys.platform in ('darwin', 'sunos5'):
664+
# posix_spawn() is a syscall on both macOS and Solaris,
665+
# and properly reports errors
665666
return True
666667

667668
# Check libc name and runtime libc version

Lib/test/support/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2059,13 +2059,14 @@ def clear_ignored_deprecations(*tokens: object) -> None:
20592059
raise ValueError("Provide token or tokens returned by ignore_deprecations_from")
20602060

20612061
new_filters = []
2062+
endswith = tuple(rf"(?#support{id(token)})" for token in tokens)
20622063
for action, message, category, module, lineno in warnings.filters:
20632064
if action == "ignore" and category is DeprecationWarning:
20642065
if isinstance(message, re.Pattern):
2065-
message = message.pattern
2066-
if tokens:
2067-
endswith = tuple(rf"(?#support{id(token)})" for token in tokens)
2068-
if message.endswith(endswith):
2066+
msg = message.pattern
2067+
else:
2068+
msg = message or ""
2069+
if msg.endswith(endswith):
20692070
continue
20702071
new_filters.append((action, message, category, module, lineno))
20712072
if warnings.filters != new_filters:

Lib/test/test_complex.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,34 @@ def test_pow(self):
269269
except OverflowError:
270270
pass
271271

272+
def test_pow_with_small_integer_exponents(self):
273+
# Check that small integer exponents are handled identically
274+
# regardless of their type.
275+
values = [
276+
complex(5.0, 12.0),
277+
complex(5.0e100, 12.0e100),
278+
complex(-4.0, INF),
279+
complex(INF, 0.0),
280+
]
281+
exponents = [-19, -5, -3, -2, -1, 0, 1, 2, 3, 5, 19]
282+
for value in values:
283+
for exponent in exponents:
284+
with self.subTest(value=value, exponent=exponent):
285+
try:
286+
int_pow = value**exponent
287+
except OverflowError:
288+
int_pow = "overflow"
289+
try:
290+
float_pow = value**float(exponent)
291+
except OverflowError:
292+
float_pow = "overflow"
293+
try:
294+
complex_pow = value**complex(exponent)
295+
except OverflowError:
296+
complex_pow = "overflow"
297+
self.assertEqual(str(float_pow), str(int_pow))
298+
self.assertEqual(str(complex_pow), str(int_pow))
299+
272300
def test_boolcontext(self):
273301
for i in range(100):
274302
self.assertTrue(complex(random() + 1e-6, random() + 1e-6))
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Restore behaviour of complex exponentiation with integer-valued exponent of
2+
type :class:`float` or :class:`complex`.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:mod:`subprocess` on Solaris now also uses :func:`os.posix_spawn()` for
2+
better performance.

Objects/complexobject.c

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,7 @@ c_powu(Py_complex x, long n)
172172
static Py_complex
173173
c_powi(Py_complex x, long n)
174174
{
175-
Py_complex cn;
176-
177-
if (n > 100 || n < -100) {
178-
cn.real = (double) n;
179-
cn.imag = 0.;
180-
return _Py_c_pow(x,cn);
181-
}
182-
else if (n > 0)
175+
if (n > 0)
183176
return c_powu(x,n);
184177
else
185178
return _Py_c_quot(c_1, c_powu(x,-n));
@@ -523,19 +516,12 @@ complex_pow(PyObject *v, PyObject *w, PyObject *z)
523516
return NULL;
524517
}
525518
errno = 0;
526-
// Check if w is an integer value that fits inside a C long, so we can
527-
// use a faster algorithm. TO_COMPLEX(w, b), above, already handled the
528-
// conversion from larger longs, as well as other types.
529-
if (PyLong_Check(w)) {
530-
int overflow = 0;
531-
long int_exponent = PyLong_AsLongAndOverflow(w, &overflow);
532-
if (int_exponent == -1 && PyErr_Occurred())
533-
return NULL;
534-
if (overflow == 0)
535-
p = c_powi(a, int_exponent);
536-
else
537-
p = _Py_c_pow(a, b);
538-
} else {
519+
// Check whether the exponent has a small integer value, and if so use
520+
// a faster and more accurate algorithm.
521+
if (b.imag == 0.0 && b.real == floor(b.real) && fabs(b.real) <= 100.0) {
522+
p = c_powi(a, (long)b.real);
523+
}
524+
else {
539525
p = _Py_c_pow(a, b);
540526
}
541527

0 commit comments

Comments
 (0)