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

Replace Superclass.__init__(self) with super().__init__() #239

Closed
gsnedders opened this issue Oct 26, 2020 · 4 comments
Closed

Replace Superclass.__init__(self) with super().__init__() #239

gsnedders opened this issue Oct 26, 2020 · 4 comments

Comments

@gsnedders
Copy link

Almost certainly needs to be opt-in, though, given both remain valid and have different semantics

@gsnedders gsnedders changed the title Replace Superclass.__init__(self) with super(Cls).__init__() Replace Superclass.__init__(self) with super().__init__() Oct 26, 2020
@daira
Copy link
Contributor

daira commented Oct 28, 2020

I don't think of this as being a Python 2 vs Python 3 thing at all. You can use either in both versions, right? And the semantics of each doesn't differ between Python 2 and 3.

@gsnedders
Copy link
Author

I don't think of this as being a Python 2 vs Python 3 thing at all.

Yeah, I guess it's more a Python 2.1 v. Python 2.2 thing (when super was introduced) 🙃

You can use either in both versions, right?

Mostly. You can only use super with new-style classes in Python 2.

And the semantics of each doesn't differ between Python 2 and 3.

Modulo the above, correct.

For context: I was looking at modernising some old code which I believe had been using old-style classes in Python 2 as at some point performance of old-style classes had been better (or at least significantly enough so for library-internal objects created in a hot loop), hence why that code wasn't using super.

@graingert
Copy link
Member

@gsnedders you should try out pyupgrade asottile/pyupgrade#305

@graingert
Copy link
Member

I think this is out of scope for modernize as Superclass.__init__(self) works on py2 and py3

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

No branches or pull requests

3 participants