<commit_before># -*- coding: utf-8 -*-
import importlib


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

        :param name:
        :type name: str
        :return:
        :rtype: simpleflow.activity.Activity
        """
        module_name, activity_name = name.rsplit('.', 1)
        module = importlib.import_module(module_name)
        return getattr(module, activity_name)
<commit_msg>dynamic_dispatcher: raise early if not an Activity<commit_after># -*- coding: utf-8 -*-
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

{'fraction_non_alphanumeric': 0.10035335689045936, 'fraction_numerical': 0.0028268551236749115, 'mean_word_length': 2.649484536082474, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1562594', 'n_tokens_mistral': 399, 'n_tokens_neox': 385, 'n_words': 104}