Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make example runnable
  • Loading branch information
slateny committed Apr 27, 2022
commit c2f649f45b5bff66044f34245c468952789885ff
17 changes: 9 additions & 8 deletions Doc/library/weakref.rst
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,15 @@ See :ref:`__slots__ documentation <slots>` for details.
existing key. Due to this, when the reference to the original key is deleted, it
also deletes the entry in the dictionary::

class T(str):
pass
k1 = T('hello')
k2 = T('hello')
d = WeakKeyDictionary()
d[k1] = 1 # d = {k1: 1}
d[k2] = 2 # d = {k1: 2}
del k1 # d = {}
>>> class T(str):
... pass
...
>>> k1, k2 = T(), T()
>>> d = WeakKeyDictionary()
>>> d[k1] = 1 # d = {k1: 1}
>>> d[k2] = 2 # d = {k1: 2}
>>> del k1 # d = {}


.. versionchanged:: 3.9
Added support for ``|`` and ``|=`` operators, specified in :pep:`584`.
Expand Down