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

Use more Pythonic super().__init__() instead of calling parent class directly #2198

Merged
merged 1 commit into from Oct 23, 2019
Merged

Conversation

jdufresne
Copy link
Contributor

No description provided.

@wiredfool
Copy link
Member

I'm not clear that super(Class, instance) is any more pythonic than the explicit parent call, at least in 2.x.

  1. it replaces an explicit MRO with an implicit MRO controlled by the child.
  2. It's ugly.

@jdufresne
Copy link
Contributor Author

Take a look at Raymond Hettinger's article "Python’s super() considered super! ".

it replaces an explicit MRO with an implicit MRO controlled by the child.

The MRO is still explicit. It is defined on the class line. The MRO and super() use a deterministic algorithm that, once understood, should not introduce surprises.

It's ugly.

I suppose that is subjective. As someone who uses super() regularly, I don't feel this way. But if the Pillow project has a coding style regarding super(), so be it.

@wiredfool
Copy link
Member

wiredfool commented Nov 8, 2016

The MRO is still explicit. It is defined on the class line. The MRO and super() use a deterministic >algorithm that, once understood, should not introduce surprises.

The MRO of super() is controlled at runtime, the MRO of the explicit parent call is determined when the code is authored. Those are two different things. This is covered in super considered super.

@jleclanche
Copy link
Contributor

Yes please, this really should be merged.

@wiredfool
Copy link
Member

wiredfool commented Jan 6, 2017

I'm still -1, given the ugly syntax required on 2.7 and the fact that a child can mess with a parent's method resolution order with super.

@jleclanche
Copy link
Contributor

@wiredfool that's exactly the point. When subclassing PIL classes, one expects those PIL classes to be calling super() appropriately.

@jdufresne
Copy link
Contributor Author

This was tagged as "Needs Rebase" by @radarhere , but was also rejected by @wiredfool. If I put in the work to rebase this will it be reconsidered for inclusion?

@radarhere
Copy link
Member

If you don't feel inspired to rebase, then I wouldn't recommend doing so, particularly with an issue like this, where there is not a lot of nuance in the implementation.

@wiredfool
Copy link
Member

I think the tag was essentially a mechanical marking of all the PRs with merge errors.

@homm
Copy link
Member

homm commented Jul 9, 2017

@wiredfool

it replaces an explicit MRO with an implicit MRO controlled by the child.

Certainly, but this is desired behaviour. Python is very flexible language and there should be a way to insert your class in the middle of MRO. Super allows this.
As of ugly syntax, you are definitely right, but this it the thing we all have to put up with for a compatibility.

@jdufresne
Copy link
Contributor Author

jdufresne commented Jul 9, 2017

If you don't feel inspired to rebase, then I wouldn't recommend doing so, particularly with an issue like this, where there is not a lot of nuance in the implementation.

I have no problem doing the work, I like contributing. So I feel plenty inspired. I just don't want to waste everyone's time (including my own) if it is known ahead of time that it will be rejected. FWIW, I still think using super() is preferable.

@jdufresne
Copy link
Contributor Author

Rebased to latest master.

@radarhere
Copy link
Member

Just to note - Python 2 is no longer supported in the next Pillow release.

@jdufresne
Copy link
Contributor Author

jdufresne commented Oct 7, 2019

Updated to use the super().__init__(...) style syntax of Python 3. This will obviously fail on Python 2 until it is removed from the test matrix. Feel free to pull this change/commit into #4109 if that is easier.

@hugovk
Copy link
Member

hugovk commented Oct 21, 2019

Any remaining objections to merging this, now the Python 2.7 ugliness has gone?

@hugovk hugovk merged commit 84fed4d into python-pillow:master Oct 23, 2019
@jdufresne jdufresne deleted the super branch October 27, 2019 13:23
@radarhere radarhere moved this from New Issues to Done in Pillow Apr 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Pillow
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

6 participants