Skip to content
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

stdlib: Add many missing dunder overrides #7231

Merged
merged 2 commits into from Feb 16, 2022

Conversation

AlexWaygood
Copy link
Member

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 than MutableMapping.__delitem__)
  • multiprocessing.pool
  • multiprocessing.managers
  • shelve.Shelf.__contains__ (signature is more restrictive than MutableMapping.__contains__, violating LSP)

@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

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

This a more precise, so a win in my eyes. I also like that we got rid of some AbstractContextManager inheritance.

@JelleZijlstra JelleZijlstra merged commit fbc279e into python:master Feb 16, 2022
@AlexWaygood AlexWaygood deleted the pos-or-kw branch February 16, 2022 14:30
@AlexWaygood
Copy link
Member Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants