[proxy] web.archive.org← back | site home | direct (HTTPS) ↗ | proxy home | ◑ dark◐ light

Issue 38761: weakref.WeakSet not instanceof collections.abc.Set

The Wayback Machine - https://web.archive.org/web/20210523104713/https://bugs.python.org/issue38761

Issue38761

classification
Title: weakref.WeakSet not instanceof collections.abc.Set
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: Nils Kattenbeck, gvanrossum, rhettinger
Priority: normal Keywords: patch

Created on 2019-11-10 11:39 by Nils Kattenbeck, last changed 2019-11-11 04:13 by rhettinger. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 17104 merged rhettinger, 2019-11-10 21:42
Messages (5)
msg356326 - (view) Author: Nils Kattenbeck (Nils Kattenbeck) * Date: 2019-11-10 11:39
Instances of weakref.WeakSet are not instances of Set and therefore not of MutableSet but they are instances of Collection.
They however implement all required methods for a MutableSet and Weak(Key|Value)Dictionary are correctly identified.
Is this just an oversight or am I missing something?


from weakref import WeakKeyDictionary, WeakValueDictionary, WeakSet
from collections.abc import MutableMapping, Collection, Set, MutableSet

wkdict = WeakKeyDictionary()
wvdict = WeakValueDictionary()
ws = WeakSet()

assert isinstance(wkdict, MutableMapping)
assert isinstance(wvdict, MutableMapping)
assert isinstance(ws, Collection)
assert not isinstance(ws, Set)
assert not isinstance(ws, MutableSet)
msg356337 - (view) Author: Raymond Hettinger (rhettinger) * Date: 2019-11-10 21:32
We could register the WeakSet in _collections_abc, right after MutableSet is defined.  That module only registered builtins so that it can avoid imports; however, since we know that WeakSet is already loaded, it is reasonable to add an import for registration purposes.

This was likely omitted because WeakSet is used in the implementation of the ABC.

Marking this as a proposed enhancement rather than as a bug because the collections ABCs are under no obligation to register anything more than the builtins.
msg356343 - (view) Author: Guido van Rossum (gvanrossum) * Date: 2019-11-10 23:37
As I wrote between the lines in the PR, this would be a bug in the weakref module, not a bug in collections.abc.
msg356349 - (view) Author: Raymond Hettinger (rhettinger) * Date: 2019-11-11 04:12
New changeset 84ac4376587e35d16b4d0977c4f330d9d04b690a by Raymond Hettinger in branch 'master':
bpo-38761: Register WeakSet as a MutableSet (GH-17104)
https://github.com/python/cpython/commit/84ac4376587e35d16b4d0977c4f330d9d04b690a
msg356350 - (view) Author: Raymond Hettinger (rhettinger) * Date: 2019-11-11 04:13
Nils, thanks for the report.

Guido, thanks for the clarification.
History
Date User Action Args
2019-11-11 04:13:30rhettingersetstatus: open -> closed
resolution: fixed
messages: + msg356350

stage: patch review -> resolved

2019-11-11 04:12:23rhettingersetmessages: + msg356349
2019-11-10 23:37:39gvanrossumsetmessages: + msg356343
2019-11-10 21:42:36rhettingersetkeywords: + patch
stage: patch review
pull_requests: + pull_request16610
2019-11-10 21:32:50rhettingersetversions: + Python 3.9, - Python 3.7
nosy: + rhettinger, gvanrossum

messages: + msg356337

assignee: rhettinger
type: enhancement

2019-11-10 11:39:15Nils Kattenbeckcreate