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

MAINT: use super() as described by PEP 3135 #18648

Merged
merged 1 commit into from
Mar 20, 2021
Merged

Conversation

mwtoews
Copy link
Contributor

@mwtoews mwtoews commented Mar 19, 2021

There are two common ways to use the super built-in:

  1. Passing both the class and instance, e.g. super(C, self), as was required for Python 2
  2. Just using super() without arguments, as described by PEP 3135, adopted in 2007 for Python 3.0

Currently there is a mixture of the two forms; find them with git grep "super([^)]" or git grep "super()". This PR refactors most of them to the PEP 3135 convention. This convention is cleaner and enforces the DRY (Don't Repeat Yourself) rule.

The two exceptions of super(cls, type) that pass a type to the second argument are in numpy/ma/core.py:

  1. L3405-L3407: @dtype.setter
  2. L3421-L3423: @shape.setter

These two instances cannot use a bare super(), and are not touched in this PR.

Copy link
Member

@seberg seberg left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM, will merge it in a bit, unless someone has a comment. I never realized you can use super() for classmethods :) (or at least didn't know)

@seberg seberg merged commit 9629cd9 into numpy:main Mar 20, 2021
@mwtoews mwtoews deleted the pep-3135 branch September 22, 2021 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants