Skip to content

Commit ede58ce

Browse files
authored
Merge branch 'main' into docs-default-args
2 parents f284c07 + f19f1d8 commit ede58ce

File tree

9 files changed

+33
-11
lines changed

9 files changed

+33
-11
lines changed

Doc/library/annotationlib.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
.. module:: annotationlib
55
:synopsis: Functionality for introspecting annotations
66

7+
.. versionadded:: 3.14
78

89
**Source code:** :source:`Lib/annotationlib.py`
910

Doc/library/mmap.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,10 @@ To map anonymous memory, -1 should be passed as the fileno along with the length
324324

325325
Return the length of the file, which can be larger than the size of the
326326
memory-mapped area.
327-
For anonymous mapping, return its size.
327+
For an anonymous mapping, return its size.
328328

329329
.. versionchanged:: next
330-
Supports anonymous mapping on Unix.
330+
Anonymous mappings are now supported on Unix.
331331

332332

333333
.. method:: tell()

Doc/library/random.rst

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,8 @@ Recipes
630630
-------
631631

632632
These recipes show how to efficiently make random selections
633-
from the combinatoric iterators in the :mod:`itertools` module:
633+
from the combinatoric iterators in the :mod:`itertools` module
634+
or the :pypi:`more-itertools` project:
634635

635636
.. testcode::
636637
import random
@@ -661,6 +662,17 @@ from the combinatoric iterators in the :mod:`itertools` module:
661662
indices = sorted(random.choices(range(n), k=r))
662663
return tuple(pool[i] for i in indices)
663664

665+
def random_derangement(iterable):
666+
"Choose a permutation where no element is in its original position."
667+
seq = tuple(iterable)
668+
if len(seq) < 2:
669+
raise ValueError('derangments require at least two values')
670+
perm = list(seq)
671+
while True:
672+
random.shuffle(perm)
673+
if all(p != q for p, q in zip(seq, perm)):
674+
return tuple(perm)
675+
664676
The default :func:`.random` returns multiples of 2⁻⁵³ in the range
665677
*0.0 ≤ x < 1.0*. All such numbers are evenly spaced and are exactly
666678
representable as Python floats. However, many other representable

Doc/tutorial/datastructures.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ objects:
6262
.. method:: list.index(x[, start[, end]])
6363
:noindex:
6464

65-
Return zero-based index in the list of the first item whose value is equal to *x*.
65+
Return zero-based index of the first occurrence of *x* in the list.
6666
Raises a :exc:`ValueError` if there is no such item.
6767

6868
The optional arguments *start* and *end* are interpreted as in the slice

Lib/test/test_interpreters/test_api.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2204,6 +2204,16 @@ def test_whence(self):
22042204
whence = eval(text)
22052205
self.assertEqual(whence, _interpreters.WHENCE_LEGACY_CAPI)
22062206

2207+
def test_contextvars_missing(self):
2208+
script = f"""
2209+
import contextvars
2210+
print(getattr(contextvars.Token, "MISSING", "'doesn't exist'"))
2211+
"""
2212+
2213+
orig = _interpreters.create()
2214+
text = self.run_and_capture(orig, script)
2215+
self.assertEqual(text.strip(), "<Token.MISSING>")
2216+
22072217
def test_is_running(self):
22082218
def check(interpid, expected):
22092219
with self.assertRaisesRegex(InterpreterError, 'unrecognized'):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix :mod:`contextvars` initialization so that all subinterpreters are assigned the
2+
:attr:`~contextvars.Token.MISSING` value.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
The :meth:`~mmap.mmap.size` method of the :class:`mmap.mmap` class now
22
returns the size of an anonymous mapping on both Unix and Windows.
33
Previously, the size would be returned on Windows and an :exc:`OSError`
4-
would be raised on Unix.
5-
Raise :exc:`ValueError` instead of :exc:`OSError` with ``trackfd=False``.
4+
would be raised on Unix. :exc:`ValueError` is now raised instead of
5+
:exc:`OSError` when ``trackfd=False``.

Objects/odictobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1519,7 +1519,7 @@ odict_init(PyObject *self, PyObject *args, PyObject *kwds)
15191519
if (len == -1)
15201520
return -1;
15211521
if (len > 1) {
1522-
const char *msg = "expected at most 1 arguments, got %zd";
1522+
const char *msg = "expected at most 1 argument, got %zd";
15231523
PyErr_Format(PyExc_TypeError, msg, len);
15241524
return -1;
15251525
}

Python/context.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,11 +1360,8 @@ get_token_missing(void)
13601360
PyStatus
13611361
_PyContext_Init(PyInterpreterState *interp)
13621362
{
1363-
if (!_Py_IsMainInterpreter(interp)) {
1364-
return _PyStatus_OK();
1365-
}
1366-
13671363
PyObject *missing = get_token_missing();
1364+
assert(PyUnstable_IsImmortal(missing));
13681365
if (PyDict_SetItemString(
13691366
_PyType_GetDict(&PyContextToken_Type), "MISSING", missing))
13701367
{

0 commit comments

Comments
 (0)