Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because fname can be both a string or a file-like, this line reads a little strangely. Would you mind adding a comment? Something along the lines of:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry to quibble, but I think that in the context of the few lines above, little or no comment is needed. At most, "file-like object: check for name with extension" or something like that.
This changeset leaves in place the likelihood of somewhat obscure error messages if the file name lacks an extension.
One could use something like this:
Too ugly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a lot to hold on to in your head. And even then passing a
fname='broken.'
would result in no extension being identified.Apart from the (admittedly necessary) use of
is_string_like
, I have no major problem with this code block. To address theIndexError
you are referring to, I would probably factor out the indexing and adding a line beforeif ext not in handlers.keys():
to the tone of:And depending on if we actually care about users who might pass
format=''
, I would probably drop theelse: ext='png'
out of the if block and do:Later on.
Of course, this is a backport, so I'm not really advocating a structural change for this PR. I do think, however, a test would be beneficial.