PyCQA / modernize

Modernizes Python code for eventual Python 3 migration. Built on top of fissix (a fork of lib2to3)
https://modernize.readthedocs.org/
Other
355 stars 51 forks source link

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

Closed gsnedders closed 4 years ago

gsnedders commented 4 years ago

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

daira commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

@gsnedders you should try out pyupgrade https://github.com/asottile/pyupgrade/issues/305

graingert commented 4 years ago

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