Small cleanups. by anntzer · Pull Request #12899 · matplotlib/matplotlib · GitHub
Skip to content

Small cleanups. - #12899

Merged
jklymak merged 1 commit into
matplotlib:masterfrom
anntzer:cleanup
Mar 3, 2019
Merged

jklymak merged 1 commit into
matplotlib:masterfrom
anntzer:cleanup

Conversation

@anntzer

@anntzer anntzer commented Nov 27, 2018

Copy link
Copy Markdown
Contributor

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@anntzer anntzer added this to the v3.1 milestone Nov 27, 2018

@WeatherGod WeatherGod left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Haven't fully reviewed this, but I noticed several problems right away that needs to be addressed first.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Personally, I like the original wording a bit better because it states what is returned, rather than implying a boolean result via the word "whether", which might be confusing for non-english-native readers.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

A quick grep shows that there's a lot of places where we're using Return whether to indicate a boolean return type (though admittedly I may be responsible for quite a few of them, as I also prefer that wording). It's also quite common in the CPython docs (for example).

raise ValueError("filename must be a path")
with cbook.open_file_cm(fname_or_fh, "w", encoding="utf-8") as file:
if not cbook.file_requires_unicode(file):
file = codecs.getwriter("utf-8")(file)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we not clobber file like this, please?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also, when reassigning a variable within a context like this, I don't think the close() gets called on the new object because the context manager is holding a reference to the original object.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Clobbering what? file is not a builtin (... anymore). And I'd say it's a much nicer variable name than fh...

The fact that the codec writer doesn't get closed doesn't matter (and anyways it will get closed by the GC), what matters is that the file itself gets closed.

import codecs
import contextlib


class filelike:  # mocks file
    def close(self):
        print("closed")


@contextlib.contextmanager
def cm():  # mocks open_file_cm
    print("enter")
    f = filelike()
    yield f
    f.close()
    print("exit")


with cm() as file:
    file = codecs.getwriter("utf-8")(file)


print("done")

prints

enter
closed
exit
done

so the file is indeed closed before the contextmanager is exited.

Comment thread lib/matplotlib/backends/backend_pgf.py
@jklymak

jklymak commented Feb 26, 2019

Copy link
Copy Markdown
Member

@WeatherGod you are blocking this. I don't think any great harm will be done if this is closed if you can't come to terms with @anntzer

@anntzer

anntzer commented Feb 26, 2019

Copy link
Copy Markdown
Contributor Author

I don't mind changing the PR either, if my replies above are not convincing enough...

@timhoffm timhoffm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

With or without further changes this is fine.

Comment thread lib/matplotlib/image.py Outdated
----------
v : bool
v : bool or None
If None, use :rc:`image.resample`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

@jklymak

jklymak commented Feb 27, 2019

Copy link
Copy Markdown
Member

Lets give @WeatherGod another day or two to respond. If not, I don't think any irrevocable harm is done by merging....

@jklymak
jklymak dismissed WeatherGod’s stale review March 3, 2019 00:37

stale review...

@jklymak

jklymak commented Mar 3, 2019

Copy link
Copy Markdown
Member

@jklymak
jklymak merged commit 7875bc5 into matplotlib:master Mar 3, 2019
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Mar 3, 2019
timhoffm added a commit that referenced this pull request Mar 3, 2019
…899-on-v3.1.x

Backport PR #12899 on branch v3.1.x (Small cleanups.)
@anntzer
anntzer deleted the cleanup branch March 3, 2019 11:03
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.

4 participants