bpo-41749: Little improve on imghdr#22166
Conversation
For the `what()` function, the `file` parameter is always needed. In despite of that users can use `h` for send a bytes stream to detect the kind of the image, the `file` parameter is need. Don't have sense ask for `file` parameter when this parameter will not any effect on the result of the `what` function.
terryjreedy
left a comment
There was a problem hiding this comment.
I am currently leaning toward rejecting the change, but if it is not, indicated changes are needed.
| with self.assertRaises(TypeError): | ||
| imghdr.what(self.testfile, 1) | ||
| with self.assertRaises(AttributeError): | ||
| with self.assertRaises(BytesWarning): |
There was a problem hiding this comment.
Given that the signature change should not affect this call, I don't understand the error change.
| @@ -0,0 +1 @@ | |||
| Allow to programmer to don't use `file` parameter on `what` on imghdr library. No newline at end of file | |||
There was a problem hiding this comment.
This needs revision, but I won't bother unless we decide to apply change.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
| #-------------------------# | ||
|
|
||
| def what(file, h=None): | ||
| def what(file='', h=None): |
There was a problem hiding this comment.
To catch 'what()' properly, the default should be a sentinel that people do not pass. Before this add
| def what(file='', h=None): | |
| _none = object() | |
| def what(file=_none, h=None): |
| f = None | ||
| try: | ||
| if h is None: | ||
| if file == '': |
There was a problem hiding this comment.
| if file == '': | |
| if file == _none: |
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
For the
what()function, thefileparameter is always needed.In despite of that users can use
hfor send a bytes stream todetect the kind of the image, the
fileparameter is need.Don't have sense ask for
fileparameter when this parameter willnot any effect on the result of the
whatfunction.bpo-41749: Little improve on imghdr
https://bugs.python.org/issue41749