<commit_before>.. image:: https://travis-ci.org/jacopofar/runtime_typecheck.svg?branch=master
    :target: https://travis-ci.org/jacopofar/runtime_typecheck
    :alt: Travis CI badge

.. image:: https://badge.fury.io/py/runtime_typecheck.svg
    :target: https://badge.fury.io/py/runtime_typecheck
    :alt: pypy version badge

runtime typecheck
#################

## __NOTE:__ this was fun to implement and I learned a lot about Python type metadata, but if you are looking for a runtime type checker look at `Pydantic<https://pydantic-docs.helpmanual.io/>`_

Checks that a value satisfies a Python 3.6 type at runtime

This code uses Python 3.6 type hints and the `typing` package to provide a simple runtime type check.


The check can be done explicitly calling the `check_type` function or with the `@check_args` function decorator which raises an exception when the argument passed to the function do not match the type hints

Example:

.. code-block:: python

    from runtime_typechecker import check_type, check_args
    from typing import Tuple
    assert check_type((1, 67), Tuple[int, int])
    assert not check_type((1, "new york"), Tuple[int, int])
    
    @check_args
    def dummy_fun(a: int = 0, b: str = '', c: Tuple[int, str] = (0, '')) -> int:
        return a + len(b) + c[0] + len(c[1]) + 7
    # this will throw a TypeException with the list of the issues. The decorated function is not even called in this case
    dummy_fun(a='1', c=(1,42))
    # this will work
    dummy_fun(a=3)


Currently not all of the components of Python 3.6 `typing` module are supported, more coming.<commit_msg>Damn RST, how does it work<commit_after>.. image:: https://travis-ci.org/jacopofar/runtime_typecheck.svg?branch=master
    :target: https://travis-ci.org/jacopofar/runtime_typecheck
    :alt: Travis CI badge

.. image:: https://badge.fury.io/py/runtime_typecheck.svg
    :target: https://badge.fury.io/py/runtime_typecheck
    :alt: pypy version badge

runtime typecheck
#################

NOTE: this was fun to implement and I learned a lot about Python type metadata, but if you are looking for a runtime type checker look at `Pydantic<https://pydantic-docs.helpmanual.io/>`_
-----------------

Checks that a value satisfies a Python 3.6 type at runtime

This code uses Python 3.6 type hints and the `typing` package to provide a simple runtime type check.


The check can be done explicitly calling the `check_type` function or with the `@check_args` function decorator which raises an exception when the argument passed to the function do not match the type hints

Example:

.. code-block:: python

    from runtime_typechecker import check_type, check_args
    from typing import Tuple
    assert check_type((1, 67), Tuple[int, int])
    assert not check_type((1, "new york"), Tuple[int, int])
    
    @check_args
    def dummy_fun(a: int = 0, b: str = '', c: Tuple[int, str] = (0, '')) -> int:
        return a + len(b) + c[0] + len(c[1]) + 7
    # this will throw a TypeException with the list of the issues. The decorated function is not even called in this case
    dummy_fun(a='1', c=(1,42))
    # this will work
    dummy_fun(a=3)


Currently not all of the components of Python 3.6 `typing` module are supported, more coming.
{'fraction_non_alphanumeric': 0.11377613776137761, 'fraction_numerical': 0.012300123001230012, 'mean_word_length': 3.694083694083694, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 10, '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': '3036634', 'n_tokens_mistral': 1039, 'n_tokens_neox': 997, 'n_words': 390}