New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
weakref.WeakSet not instanceof collections.abc.Set #82942
Comments
Instances of weakref.WeakSet are not instances of Set and therefore not of MutableSet but they are instances of Collection. from weakref import WeakKeyDictionary, WeakValueDictionary, WeakSet
from collections.abc import MutableMapping, Collection, Set, MutableSet
wkdict = WeakKeyDictionary()
wvdict = WeakValueDictionary()
ws = WeakSet() assert isinstance(wkdict, MutableMapping) |
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. |
As I wrote between the lines in the PR, this would be a bug in the weakref module, not a bug in collections.abc. |
Nils, thanks for the report. Guido, thanks for the clarification. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: