Filename might be None, do not try to pass that to os.path.basename.

See #486