On 7/19/2018 4:32 AM, Stephen J. Turnbull wrote:
Chris Angelico writes later in thread:
> On Thu, Jul 19, 2018 at 9:55 AM, Giampaolo Rodola' <g.rod...@gmail.com>
wrote:
> Personally, I'm +0 on this. It'd be a few small wins here and there,
> nothing huge, and I could easily live without it; but it's something
> that I know some people will love.
I am 100% in sync with the reasoning, but -0 on the PEP (and only that
high because the advocates are so passionate).
To be honest, code transformations like this
> class BaseUploadObject(object):
> def find_content_type(self, filename):
> ctype, encoding = mimetypes.guess_type(filename)
> if ctype is None:
> return 'application/octet-stream'
> else:
> return ctype
to this
> class BaseUploadObject(object):
> def find_content_type(self, filename):
> ctype, encoding = mimetypes.guess_type(filename)
> return ctype ?? 'application/octet-stream'
make me cringe. Exactly one of two things is true:
It seems to me that the problem is returning None. Guess_type should
have default='application/octet-stream' (or whatever *is* the default)
in its signature.
The premise of returning None as default is that users can follow with
conditional code. If we now think that this is too much of a burden, we
should stop returning None, at least by default.
1. mimetypes.guess_type guarantees that the only falsie it will ever
return is None, or
2. it doesn't.
or
3. it never returns anything other than a non-blank string unless the
user so requests.
--
Terry Jan Reedy
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/