Skip to content

Conversation

@lysnikolaou
Copy link
Member

@lysnikolaou lysnikolaou commented Jan 23, 2026

.. versionchanged:: 3.8
Dictionaries are now reversible.

.. admonition:: Thread safety
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I

Suggested change
.. admonition:: Thread safety
.. _thread-safety-dict:
.. rubric:: Thread safety for dict objects

Admonition will create a big box which will not be good considering the size of the text. A rubric is like a title but without being it in the sidebar and a label allows us to link it.

Alternatively we can have a real section.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consistency with list is a tiny bit more important here, I feel. Especially since we're planning to migrate all of this content into a new page.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say that it is still wrong to have an admonition, especially considering how it is rendered online (it is, to me, disruptive to have a huge wall of text with borders and a colored background).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tend to agree about the HTML rendering. Maybe removing it from list as well makes the most sense then?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

@lysnikolaou
Copy link
Member Author

Could we have some more reviews on the content here?

cc @encukou if you have some spare cycles

@encukou encukou self-requested a review January 30, 2026 13:30
argument is a :class:`dict`, :class:`tuple`, :class:`set` or
:class:`frozenset`.

The following operations and function are lock-free and
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to define “lock-free”? (And/or “per-object lock”?)
Like “thread-safe” and “atomic”, I kinda know what that means, but if this was underlined I'd click through to read the definition.

execute arbitrary Python code. During such comparisons, the dictionary may
be modified by another thread. For built-in types like :class:`str`,
:class:`int`, and :class:`float`, that implement :meth:`~object.__eq__` in C,
the underlying lock is not released during comparisons and this is not a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An “underlying lock” in lock-free operations is rather confusing.

considerations as above apply.

The following operations return new objects and hold the per-object lock
for the duration:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for the duration:
for the duration of the operation:

Comment on lines +5588 to +5589
The equality comparison also compares values using :meth:`~object.__eq__`,
so for non-built-in types the lock may be released during comparison.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This goes for != as well, right? I'd either add a small hint:

Suggested change
The equality comparison also compares values using :meth:`~object.__eq__`,
so for non-built-in types the lock may be released during comparison.
The equality comparisons also compare values using :meth:`~object.__eq__`,
so for non-built-in types the lock may be released during comparison.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or spell it out:

Suggested change
The equality comparison also compares values using :meth:`~object.__eq__`,
so for non-built-in types the lock may be released during comparison.
The equality and inequality comparison also compares values using
:meth:`~object.__eq__`, so for non-built-in types the lock may be released
during comparison.

Comment on lines +5608 to +5610
d.update(iterable) # iterable is not a dict
d |= iterable # iterable is not a dict
dict.fromkeys(iterable) # iterable is not a dict/set/frozenset
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to rely too much on the :class: maybe. (The red/green distinction is completely invisible to colourblind people, not to mention screen reader users.)

Suggested change
d.update(iterable) # iterable is not a dict
d |= iterable # iterable is not a dict
dict.fromkeys(iterable) # iterable is not a dict/set/frozenset
d.update(iterable) # iterable is not a dict: only d locked
d |= iterable # iterable is not a dict: only d locked
dict.fromkeys(iterable) # iterable is not a dict/set/frozenset: only result locked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

3 participants