Issue #418: guess_file_type raises error instead of None if python-magic is not installed. (blais/beancount)

10 views
Skip to first unread message

cevans

unread,
Feb 7, 2020, 8:26:17 AM2/7/20
to bean...@googlegroups.com
New issue 418: guess_file_type raises error instead of None if python-magic is not installed.
https://bitbucket.org/blais/beancount/issues/418/guess_file_type-raises-error-instead-of

cevans:

Documentation for `guess_file_type` notes that it will return `None` if it can’t guess the file’s type. However, if python-magic is not available, and it can’t recognize a file, it raises a `ValueError`. This isn’t necessarily desirable: `mimetypes` may sufficiently recognize all the file types the user wants to recognize, but files that the user doesn’t care about positively recognizing through `guess_file_type` will break importers for other files that use it.

In my use case, I have many files that are easily recognized by `mimetypes` \(pdf, csv\), but one importer that uses something else \(asp…\). The importer using that doesn’t rely on `guess_file_type` for identification, other importers that do break when there is an asp file there and they try to identify it \(eg, when using fava\).

The function already uses warnings, so it would make sense to replace the error with a warning, and return `None` if the file has not already been recognized and python-magic is not available.


Reply all
Reply to author
Forward
0 new messages