Small cleanups. - #12899
Small cleanups.#12899
Conversation
WeatherGod
left a comment
There was a problem hiding this comment.
Haven't fully reviewed this, but I noticed several problems right away that needs to be addressed first.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Can we not clobber file like this, please?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
@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 |
|
I don't mind changing the PR either, if my replies above are not convincing enough... |
timhoffm
left a comment
There was a problem hiding this comment.
With or without further changes this is fine.
| ---------- | ||
| v : bool | ||
| v : bool or None | ||
| If None, use :rc:`image.resample`. |
There was a problem hiding this comment.
It would be nice to give the default rcParams setting:
https://matplotlib.org/devdocs/devel/documenting_mpl.html?highlight=documenting#rcparams
|
Lets give @WeatherGod another day or two to respond. If not, I don't think any irrevocable harm is done by merging.... |
…899-on-v3.1.x Backport PR #12899 on branch v3.1.x (Small cleanups.)

PR Summary
PR Checklist