def __call__(self, v): try: set_v = set(v) except Exception as e: raise TypeInvalid(self.msg or 'cannot be presented as set: {0}'.format(e)) return set_v
def __call__(self, v): try: set_v = set(v) except TypeError as e: raise TypeInvalid(self.msg or 'contains unhashable elements: {0}'.format(e)) if len(set_v) != len(v): seen = set() dupes = list(set(x for x in v if x in seen or seen.add(x))) raise Invalid(self.msg or 'contains duplicate items: {0}'.format(dupes)) return v