[Python-Dev] mimetypes.guess_all_extensions()

Barry Warsaw barry@python.org
09 Jun 2003 16:55:34 -0400


I think mimetypes.guess_all_extensions() is broken in its return value
when there are no matching extensions.  Currently it returns None when
there are no matching extensions[*], but I think it would be better to
simply return an empty list.  I have an application where I want to
iterate over the return values, but I have to add a (IMO) useless hack:

for ext in guess_all_extensions(mytype, strict=False) or []:
   # blah

Seems like this would be a common use case.  So what does returning None
instead of an empty list buy you anyway?  Since both are false, it
should be fine to just remove the last two lines of the method.

This method is new in Python 2.3 so I don't think backwards
compatibility should be an issue.  It's a simple fix; are there any
objections?

-Barry

[*] The way the method returns None in the no-match case is bogus
anyway.  IMO, it shouldn't return None implicitly simply by virtue of
falling off the end of the def.