import importlib

from simpleflow.activity import Activity

from .exceptions import DispatchError


class Dispatcher(object):
    """
    Dispatch by name, like simpleflow.swf.process.worker.dispatch.by_module.ModuleDispatcher
    but without a hierarchy.
    """
    @staticmethod
    def dispatch_activity(name):
        """

        :param name:
        :type name: str
        :return:
        :rtype: Activity
        :raise DispatchError: if doesn't exist or not an activity
        """
        module_name, activity_name = name.rsplit('.', 1)
        module = importlib.import_module(module_name)
        activity = getattr(module, activity_name, None)
        if not isinstance(activity, Activity):
            raise DispatchError()
        return activity

import importlib

from simpleflow.activity import Activity

from .exceptions import DispatchError


class Dispatcher(object):
    """
    Dispatch by name, like simpleflow.swf.process.worker.dispatch.by_module.ModuleDispatcher
    but without a hierarchy.
    """
    @staticmethod
    def dispatch_activity(name):
        """

        :param name:
        :type name: str
        :return:
        :rtype: Activity
        :raise DispatchError: if doesn't exist or not an activity
        """
        module_name, activity_name = name.rsplit('.', 1)
        module = importlib.import_module(module_name)
        activity = getattr(module, activity_name, None)
        if not isinstance(activity, Activity):
            raise DispatchError("dispatching '{}' resulted in: {}".format(name, activity))
        return activity

Improve error message on DispatchError's
Improve error message on DispatchError's

  import importlib
  
  from simpleflow.activity import Activity
  
  from .exceptions import DispatchError
  
  
  class Dispatcher(object):
      """
      Dispatch by name, like simpleflow.swf.process.worker.dispatch.by_module.ModuleDispatcher
      but without a hierarchy.
      """
      @staticmethod
      def dispatch_activity(name):
          """
  
          :param name:
          :type name: str
          :return:
          :rtype: Activity
          :raise DispatchError: if doesn't exist or not an activity
          """
          module_name, activity_name = name.rsplit('.', 1)
          module = importlib.import_module(module_name)
          activity = getattr(module, activity_name, None)
          if not isinstance(activity, Activity):
-             raise DispatchError()
+             raise DispatchError("dispatching '{}' resulted in: {}".format(name, activity))
          return activity
  
Improve error message on DispatchError's
## Code Before:
import importlib

from simpleflow.activity import Activity

from .exceptions import DispatchError


class Dispatcher(object):
    """
    Dispatch by name, like simpleflow.swf.process.worker.dispatch.by_module.ModuleDispatcher
    but without a hierarchy.
    """
    @staticmethod
    def dispatch_activity(name):
        """

        :param name:
        :type name: str
        :return:
        :rtype: Activity
        :raise DispatchError: if doesn't exist or not an activity
        """
        module_name, activity_name = name.rsplit('.', 1)
        module = importlib.import_module(module_name)
        activity = getattr(module, activity_name, None)
        if not isinstance(activity, Activity):
            raise DispatchError()
        return activity

## Instruction:
Improve error message on DispatchError's
## Code After:
import importlib

from simpleflow.activity import Activity

from .exceptions import DispatchError


class Dispatcher(object):
    """
    Dispatch by name, like simpleflow.swf.process.worker.dispatch.by_module.ModuleDispatcher
    but without a hierarchy.
    """
    @staticmethod
    def dispatch_activity(name):
        """

        :param name:
        :type name: str
        :return:
        :rtype: Activity
        :raise DispatchError: if doesn't exist or not an activity
        """
        module_name, activity_name = name.rsplit('.', 1)
        module = importlib.import_module(module_name)
        activity = getattr(module, activity_name, None)
        if not isinstance(activity, Activity):
            raise DispatchError("dispatching '{}' resulted in: {}".format(name, activity))
        return activity
