10000 Cleanup stack by timhoffm · Pull Request #16326 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Cleanup stack #16326

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

Merged
merged 1 commit into from
Feb 3, 2020
Merged

Cleanup stack #16326

merged 1 commit into from
Feb 3, 2020

Conversation

timhoffm
Copy link
Member
@timhoffm timhoffm commented Jan 25, 2020

PR Summary

  • Docstrings
  • self._elements is a list. The canoncial non-empty check is if not self._emenents rather thatn if not len(self._elements).
  • use the more explicit list.copy() instead of list[:] (available since Python 3.3).
  • some renaming of local variables for more clarity:
    • old -> old_elements
    • bubbles -> top_elements
    • thiso -> elem

Note: bubble() and clear() can be implemented much more efficiently. But that's for another PR because I'd also have to write tests for that.

@timhoffm timhoffm added this to the v3.3.0 milestone Jan 25, 2020
self.push(thiso)
for _ in bubbles:
self.push(elem)
for _ in top_elements:
self.push(o)
return o
Copy link
Contributor
@anntzer anntzer Jan 25, 2020

Choose a reason for hiding this comment

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

Shorter would be something like

count = self._elements.count(o)
if not count: ...
self._elements = [e for e in self._elements if e != o] + n * [o]

no?
Edit: well, perhaps not, _pos would also need to be adjusted.

Copy link
Member Author
@timhoffm timhoffm Jan 25, 2020

Choose a reason for hiding this comment

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

That's what I meant with "should be tested". I believe that there are subtle differences if you have objects that are equal but not identical. Not that I think the sematics for that is considered in the design and well defined, but I don't want to change this without really thinking about it.

Not going to do this right now as part of this PR.

Copy link
Contributor
@anntzer anntzer left a comment

Choose a reason for hiding this comment

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

postci

Copy link
Member
@jklymak jklymak left a comment

Choose a reason for hiding this comment

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

I guess I'm somewhat leery of maintenance PRs that don't have 100% test coverage, unless there is a good reason they can't be tested.

@timhoffm
Copy link
Member Author
timhoffm commented Feb 3, 2020

Fundamentally I agree, but strictly requiring test coverage will reduce changes to the code (e.g. I wouldn't have cleaned this up, if I would have to write test code first).

There's a trade-off between the benefit of code cleanup and the risk of breaking something. Therefore, I'v restricted this PR to very basic changes, detailed in the first commit. I think they are easy enough to follow, so that the risk of breaking something is small enough.

@Kojoley Kojoley merged commit eeec25c into matplotlib:master Feb 3, 2020
@timhoffm timhoffm deleted the stack branch February 3, 2020 20:23
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.

4 participants
0