Comment 3 for bug 191963

Revision history for this message
Martin Pitt (pitti) wrote :

I don't think that this is a duplicate. The code does

        if attachments is None:
            attachments = set()
        if isinstance(attachments, LPAttachment):
            self.__attachments = set([attachments])
        else:
            if not any(map(lambda x: isinstance(x, LPAttachment), attachments)):
                raise ValueError, "Unsupported attachment-type '%s'" %type(attachments)
            self.__attachments = set(attachments)

I. e. if attachments is the empty set (if none was given), then any(empty set) is false, and thus the exception is raised.

I did a quick fix:

            if attachments and not any(map(lambda x: isinstance(x, LPAttachment), attachments)):

but the if/else clauses should be restructured. On hindsight, it would probably be better to write

  if attachment is None:
  ...
  elif isinstance(attachments, LPAttachment):
  ...
  else
   ... # check set items