stdlib: Add many missing dunder overrides #7231
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR proposes adding many missing dunder overrides in the stdlib.
Most of these have been omitted because they have similar signatures to the same method in a superclass. However, for all of these methods, the subclass override means that the method can be called with positional-or-keyword arguments, whereas the same method in the superclass can only be called with positional arguments.
It's not a particularly important difference, but, with a patch I'm writing for stubtest (which has other, better effects!), it starts complaining about all of these.
For the vast majority of these, the signature is the same as without this patch applied (modulo the change from positional-only parameters to positional-or-keyword). However, there are a few exceptions where I spotted that a change in signature was required:
collections.Counter.__delitem__
(has a more permissive signature thanMutableMapping.__delitem__
)multiprocessing.pool
multiprocessing.managers
shelve.Shelf.__contains__
(signature is more restrictive thanMutableMapping.__contains__
, violating LSP)