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

Rewrite old-style-class super calls #320

Merged
merged 4 commits into from Sep 25, 2021
Merged

Rewrite old-style-class super calls #320

merged 4 commits into from Sep 25, 2021

Conversation

asottile
Copy link
Owner

No description provided.

@asottile asottile changed the title New class super v2 Rewrite old-style-class super calls Jun 19, 2020
@ThiefMaster
Copy link

I think this kind of rewriting may be dangerous or at least not what people expect (so being able to opt-in/out from it would probably be good).

For example, in my application we make heavy use of method calls of parent classes access checks. Usually we call the methods of all parent classes (sometimes in a specific order to being very explicit is beneficial), sometimes only one of them (because we explicitly do not want the access check from the other parent), and sometimes there is only one parent class.

And the code here looks like my last case would always be rewritten, but that would make the code base inconsistent depending on how many parent classes there are - and I believe some place in the Python docs even tells you to avoid mixing super and classic parent method calling within a single inheritance chain.

@asottile
Copy link
Owner Author

@ThiefMaster your assumption is incorrect, this rewrite will only happen when:

  • the class has a single unambigous base
  • the call is not within another scope (lambda, nested function, comprehension)
  • the function name exactly matches the current function

in this case the call to super() is identical and safe. there will not be an option for this -- if you don't want this then fork the tool

@asottile asottile marked this pull request as ready for review September 25, 2021 20:19
@asottile asottile merged commit b3f8c7b into master Sep 25, 2021
@asottile asottile deleted the new_class_super_v2 branch September 25, 2021 20:27
asottile added a commit that referenced this pull request Sep 28, 2021
This reverts commit b3f8c7b, reversing
changes made to 4130821.
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

2 participants