<jupyter_start><jupyter_text>Decoators Part One<jupyter_code>def counter(fn):
    count = 0

    def inner(*args, **kwargs):
        nonlocal count
        count += 1
        print('Function {0} (id={1} was called {2} times'.format(fn.__name__, id(fn), count))
        return fn(*args, **kwargs)

    return inner
def add(a:int, b:int = 0):
    """
    adds two values
    """

    return a + b
help(add)
id (add)
add = counter(add)
id(add)
help(add)
add(10, 20)
add(20, 40)
add(10)
def mult(a: int, b: int, c: int = 1, *, d):
    """multiplies four values

    Args:
        a (int): [description]
        b (int): [description]
        d ([type]): [description]
        c (int, optional): [description]. Defaults to 1.
    """

    return a * b * c * d

mult(1, 2, 3, d=4)
mult(1, 2, d=3)
mult = counter(mult)
help(mult)
mult(1, 2, 3, d=4)
# This combines two steps: #1 = (35), #2 = (41)  # see #46 for less code
def my_func(s: str, i: int) -> str:
    return s * i
my_func = counter(my_func)
my_func('a', 10)
help(my_func)
#  or this way
@counter
def my_func(s: str, i: int) -> str:
    return s * i
help(my_func)
my_func('a', 10)
help(my_func)
def counter(fn):
    count = 0

    def inner(*args, **kwargs):
        """[This is the inner closure]

        Returns:
            [type]: [description]
        """
        nonlocal count
        count += 1
        print('Function {0} (id={1} was called {2} times'.format(fn.__name__, id(fn), count))
        return fn(*args, **kwargs)
    inner.__name__ = fn__name__
    inner.__doc__ = fn.__doc__

    return inner
def mult(a: int, b: int, c: int = 1, *, d):
    """multiplies four values

    Args:
        a (int): [description]
        b (int): [description]
        d ([type]): [description]
        c (int, optional): [description]. Defaults to 1.
    """

    return a * b * c * d

mult = counter(mult)
help(mult)<jupyter_output>Help on function inner in module __main__:

inner(*args, **kwargs)
    [This is the inner closure]
    
    Returns:
        [type]: [description]
{'fraction_non_alphanumeric': 0.1603541564190851, 'fraction_numerical': 0.023610427939006393, 'mean_word_length': 2.5809859154929575, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, '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}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '564016', 'license': 'Unlicense', 'n_tokens_mistral': 770, 'n_tokens_neox': 728, 'n_words': 231, 'path': 'my_classes/ScopesClosuresAndDecorators/decorators1.ipynb', 'repo_name': 'minefarmer/deep-Dive-1', 'size': '2033'}