Skip to content

Commit 2b9e711

Browse files
committed
Improve wording around atomicity; specify exact types
1 parent 2292896 commit 2b9e711

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

Doc/library/stdtypes.rst

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,21 +1475,20 @@ application).
14751475
lst[i:j] = iterable
14761476
14771477
The :meth:`~list.index` and :meth:`~list.count` methods, and the ``in``
1478-
operator, iterate the list without holding a lock. They are safe to call
1478+
operator, iterate the list without holding a lock. They are safe to call
14791479
concurrently but may return results affected by concurrent modifications.
14801480

1481-
:meth:`~list.extend` is always atomic with respect to the target list.
1482-
However, the operation is fully atomic only when the iterable that's passed
1483-
to ``extend`` is a :class:`list`, a :class:`tuple`, a :class:`set`, a
1484-
:class:`frozenset`, a :class:`dict` or a
1485-
:ref:`dictionary view object <dict-views>`. Otherwise, an iterator is
1486-
created which can be concurrently modified by another thread. The same
1487-
applies to inplace concatenation of list with other iterables when using
1488-
``lst += iterable``.
1489-
1490-
Similarly, assigning to a list slice with ``lst[i:j] = iterable`` is always
1491-
atomic with respect to the target list, but ``iterable`` is only locked when
1492-
it is also a :class:`list`.
1481+
:meth:`~list.extend` is safe to call from multiple threads. However, the
1482+
operation is fully atomic only when the iterable that's passed to ``extend``
1483+
is a :class:`list`, a :class:`tuple`, a :class:`set`, a :class:`frozenset`,
1484+
a :class:`dict` or a :ref:`dictionary view object <dict-views>` (but not
1485+
their subclasses). Otherwise, an iterator is created which can be
1486+
concurrently modified by another thread. The same applies to inplace
1487+
concatenation of list with other iterables when using ``lst += iterable``.
1488+
1489+
Similarly, assigning to a list slice with ``lst[i:j] = iterable`` is safe
1490+
to call from multiple threads, but ``iterable`` is only locked when it is
1491+
also a :class:`list` (but not its subclasses).
14931492

14941493
Operations that involve multiple accesses, as well as iteration, are not
14951494
atomic. For example:

0 commit comments

Comments
 (0)