<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get(self, thing: type):
 """ Get an instance of some type. """

        if thing in self.instances:
            return self.instances[thing]

        if thing in self.factories:
            fact = self.factories[thing]
            ret = self.get(fact)
            if hasattr(fact, '__di__') and fact.__di__['singleton']:
                self.instances[thing] = ret
            return ret

        if inspect.isclass(thing):
            return self._call_class_init(thing)
        elif callable(thing):
            return self.call(thing)

        raise DiayException('cannot resolve: %r' % thing)