<commit_before>import inspect

from snakeguice.binder import Binder, Key
from snakeguice.decorators import GuiceData as _GuiceData


class ProvidesBinderHelper(object):

    def __init__(self, injector):
        self._injector = injector

    def bind_providers(self, module, binder):
        members = [m for m in inspect.getmembers(module)
                   if inspect.ismethod(m[1])]
        for name, method in members:
            if hasattr(method.im_func, '__guice_provides__'):
                type = method.__guice_provides__
                provider = self._build_provider(module, type, method)
                binder.bind(type, to_provider=provider)

    def _build_provider(self, module, type, method):
        helper_self = self
        class GenericProvider(object):
            def get(self):
                kwargs = {}
                method_name = method.__name__
                guice_data = _GuiceData.from_class(module.__class__)
                injectable_args = guice_data.methods.get(method_name, {})
                for name, guicearg in injectable_args.items():
                    kwargs[name] = helper_self._injector.get_instance(
                            guicearg.datatype, guicearg.annotation)
                return method(**kwargs)
        return GenericProvider


class Injector(object):

    def __init__(self, modules, binder=None, stage=None):
        if not hasattr(modules, '__iter__'):
            modules = [modules]

        if binder:
            self._binder = binder.create_child(self)
        else:
            self._binder = Binder(self)
        self._stage = stage

        provides_helper = ProvidesBinderHelper(self)
        for module in modules:<commit_msg>eliminated duplicate logic<commit_after>import inspect

from snakeguice.binder import Binder, Key
from snakeguice.decorators import GuiceData as _GuiceData


class ProvidesBinderHelper(object):

    def __init__(self, injector):
        self._injector = injector

    def bind_providers(self, module, binder):
        members = [m for m in inspect.getmembers(module)
                   if inspect.ismethod(m[1])]
        for name, method in members:
            if hasattr(method.im_func, '__guice_provides__'):
                type = method.__guice_provides__
                provider = self._build_provider(module, type, method)
                binder.bind(type, to_provider=provider)

    def _build_provider(self, module, type, method):
        helper_self = self
        class GenericProvider(object):
            def get(self):
                kwargs = {}
                method_name = method.__name__
                guice_data = _GuiceData.from_class(module.__class__)
                injectable_args = guice_data.methods.get(method_name, {})
                for name, guicearg in injectable_args.items():
                    kwargs[name] = helper_self._injector.get_instance(
                            guicearg.datatype, guicearg.annotation)
                return method(**kwargs)
        return GenericProvider


class Injector(object):

    def __init__(self, modules, binder=None, stage=None):
        if not hasattr(modules, '__iter__'):
            modules = [modules]

        if not binder:
            binder = Binder(self)

        self._binder = binder
        self._stage = stage

        provides_helper = ProvidesBinderHelper(self)
        for module in modules:
{'fraction_non_alphanumeric': 0.08090614886731391, 'fraction_numerical': 0.0005884083553986466, 'mean_word_length': 2.177570093457944, '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': '6307286', 'n_tokens_mistral': 954, 'n_tokens_neox': 908, 'n_words': 215}