def set(self, value, policy=None):
        """TODO: doc set()"""
        pairs = to_pairs(value)
        self._reset()

        if policy is not None:
            assert policy in ('strict', 'subset', 'duck')
        else:
            policy = self.policy

        fields = self.field_schema_mapping
        seen = set()
        converted = True
        for key, value in pairs:
            if key not in fields:
                if policy != 'duck':
                    raise KeyError(
                        'Dict %r schema does not allow key %r' % (
                            self.name, key))
                continue
            if dict.__contains__(self, key):
                converted &= self[key].set(value)
            else:
                self[key] = el = fields[key]()
                converted &= el.set(value)
            seen.add(key)

        if policy == 'strict':
            required = set(fields.iterkeys())
            if seen != required:
                missing = required - seen
                raise TypeError(
                    'strict-mode Dict requires all keys for '
                    'a set() operation, missing %s.' % (
                        ','.join(repr(key) for key in missing)))
        return converted
dataset/ETHPy150Open jek/flatland/flatland/schema/containers.py/Dict.set/original