<commit_before>__author__ = "<NAME> <<EMAIL>>"
__date__ = "$Jul 23, 2014 16:24:36 EDT$"


import functools
import types

import PyQt4.QtCore


def update_wrapper(wrapper,
                   wrapped,
                   assigned = functools.WRAPPER_ASSIGNMENTS,
                   updated = functools.WRAPPER_UPDATES):
    """
        Extends functools.update_wrapper to ensure that it stores the wrapped function in the attribute __wrapped__.

        Args:
            wrapper(callable):      the replacement callable.

            wrapped(callable):      the callable that is being wrapped.

            assigned(tuple):        is a tuple naming the attributes assigned directly
                                    from the wrapped function to the wrapper function (defaults to
                                    functools.WRAPPER_ASSIGNMENTS)

            updated(tuple):         is a tuple naming the attributes of the wrapper that
                                    are updated with the corresponding attribute from the wrapped
                                    function (defaults to functools.WRAPPER_UPDATES)

        Returns:
            (callable):             the wrapped callable.
    """

    wrapper = functools.update_wrapper(wrapper, wrapped, assigned = assigned, updated = updated)

    # Store the underlying callable. Automatic in Python 3.
    setattr(wrapper, "__wrapped__", getattr(wrapper, "__wrapped__", wrapped))

    return(wrapper)


def wraps(wrapped,
          assigned = functools.WRAPPER_ASSIGNMENTS,
          updated = functools.WRAPPER_UPDATES):
    """
        Builds on functools.wraps to ensure that it stores the wrapped function in the attribute __wrapped__.

        Args:
            wrapped(callable):      the callable that is being wrapped.

            assigned(tuple):        is a tuple naming the attributes assigned directly
                                    from the wrapped function to the wrapper function (defaults to
                                    functools.WRAPPER_ASSIGNMENTS)

            updated(tuple):         is a tuple naming the attributes of the wrapper that
                                    are updated with the corresponding attribute from the wrapped
                                    function (defaults to functools.WRAPPER_UPDATES)

        Returns:
            (callable):             a decorator for callable, which will contain wrapped.
    """

    return(functools.partial(update_wrapper, wrapped = wrapped, assigned = assigned, updated = updated))


def static_variables(**kwargs):
    """
        Returns a decorator that decorates a callable such that it has the given static variables set.

        Args:
            *kwargs(tuple):     keyword args will be set to the value provided.

        Returns:
            (decorator):        a decorator for the callable.

    """

    def static_variables_tie(callable):
        """
            Decorates a function such that it has the given static variables set.

            Args:
                callable(callable):       the callable to decorate.

            Returns:
                (callable):               the callable returned.

        """

        for each_kwd, each_val in kwargs.items():
            setattr(callable, each_kwd, each_val)

        return(callable)

    return(static_variables_tie)


def metaclass(meta):
    """
        Returns a decorator that decorates a class such that the given metaclass is applied.
<commit_msg>nanshe/nanshe/generic_decorators.py: For the function `static_variables_tie`, rename `callable` to `a_callable`.<commit_after>__author__ = "<NAME> <<EMAIL>>"
__date__ = "$Jul 23, 2014 16:24:36 EDT$"


import functools
import types

import PyQt4.QtCore


def update_wrapper(wrapper,
                   wrapped,
                   assigned = functools.WRAPPER_ASSIGNMENTS,
                   updated = functools.WRAPPER_UPDATES):
    """
        Extends functools.update_wrapper to ensure that it stores the wrapped function in the attribute __wrapped__.

        Args:
            wrapper(callable):      the replacement callable.

            wrapped(callable):      the callable that is being wrapped.

            assigned(tuple):        is a tuple naming the attributes assigned directly
                                    from the wrapped function to the wrapper function (defaults to
                                    functools.WRAPPER_ASSIGNMENTS)

            updated(tuple):         is a tuple naming the attributes of the wrapper that
                                    are updated with the corresponding attribute from the wrapped
                                    function (defaults to functools.WRAPPER_UPDATES)

        Returns:
            (callable):             the wrapped callable.
    """

    wrapper = functools.update_wrapper(wrapper, wrapped, assigned = assigned, updated = updated)

    # Store the underlying callable. Automatic in Python 3.
    setattr(wrapper, "__wrapped__", getattr(wrapper, "__wrapped__", wrapped))

    return(wrapper)


def wraps(wrapped,
          assigned = functools.WRAPPER_ASSIGNMENTS,
          updated = functools.WRAPPER_UPDATES):
    """
        Builds on functools.wraps to ensure that it stores the wrapped function in the attribute __wrapped__.

        Args:
            wrapped(callable):      the callable that is being wrapped.

            assigned(tuple):        is a tuple naming the attributes assigned directly
                                    from the wrapped function to the wrapper function (defaults to
                                    functools.WRAPPER_ASSIGNMENTS)

            updated(tuple):         is a tuple naming the attributes of the wrapper that
                                    are updated with the corresponding attribute from the wrapped
                                    function (defaults to functools.WRAPPER_UPDATES)

        Returns:
            (callable):             a decorator for callable, which will contain wrapped.
    """

    return(functools.partial(update_wrapper, wrapped = wrapped, assigned = assigned, updated = updated))


def static_variables(**kwargs):
    """
        Returns a decorator that decorates a callable such that it has the given static variables set.

        Args:
            *kwargs(tuple):     keyword args will be set to the value provided.

        Returns:
            (decorator):        a decorator for the callable.

    """

    def static_variables_tie(a_callable):
        """
            Decorates a function such that it has the given static variables set.

            Args:
                a_callable(callable):     the callable to decorate.

            Returns:
                (callable):               the callable returned.

        """

        for each_kwd, each_val in kwargs.items():
            setattr(a_callable, each_kwd, each_val)

        return(a_callable)

    return(static_variables_tie)


def metaclass(meta):
    """
        Returns a decorator that decorates a class such that the given metaclass is applied.

{'fraction_non_alphanumeric': 0.05966350911918564, 'fraction_numerical': 0.003958716244874877, 'mean_word_length': 1.8721071863580998, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2746055', 'n_tokens_mistral': 1797, 'n_tokens_neox': 1684, 'n_words': 598}