<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def set_factory(self, thing: type, value, overwrite=False):
 """ Set the factory for something. """

        if thing in self.factories and not overwrite:
            raise DiayException('factory for %r already exists' % thing)
        self.factories[thing] = value