Skip to content

Commit

Permalink
Make mime type guessing functions more reader-friendly
Browse files Browse the repository at this point in the history
Leaving an empty "else" execution path, requiring the reader to know
that the default return value is None, seems needlessly confusing.
  • Loading branch information
michaelweiser committed Aug 31, 2018
1 parent 69decd9 commit a225cd1
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions peekaboo/toolbox/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@
def guess_mime_type_from_file_contents(file_path):
""" Get type from file magic bytes. """
mt = magic.from_file(file_path, mime=True)
if mt:
return mt
if not mt:
return None

return mt


def guess_mime_type_from_filename(file_path):
Expand All @@ -48,5 +50,7 @@ def guess_mime_type_from_filename(file_path):
mimetypes.add_type('application/javascript', '.jse')

mt = mimetypes.guess_type(file_path)[0]
if mt:
return mt
if not mt:
return None

return mt

0 comments on commit a225cd1

Please sign in to comment.