RussBaz / enforce

Python 3.5+ runtime type checking for integration testing and data validation
543 stars 21 forks source link

Added Basic Config #12

Closed TheDataLeek closed 8 years ago

TheDataLeek commented 8 years ago

In reference to issue #10 I implemented basic configuration. As of right now the parts that work are enabling/disabling based on groups or globally, but not the recursion depth or iteration size. I wanted to get your feedback on these proposed changes before adding in those other variables (they will be harder to include)

The basic API is as follows.

To enable all runtime_validation decorators globally (to disable set to False)

enforce.config(enable=True)

To enable a group globally (again, to disable set to False)

enforce.set_group('foo', True)

To tag a decorator as part of a group use the group keyword.

@runtime_validation(group='foo')
def testfunc(a: typing.Any): return a

To enable a decorator locally

@runtime_validation(enable=True)
def testfunc(a: typing.Any): return a

Now this is super nice, as it now means that you can tag a bunch of validation decorators as something like "testing" and enable them only for the unittests.

The disabling is done via the built-in functionality on the wrapt library, referenced here: https://wrapt.readthedocs.io/en/latest/decorators.html#dynamically-disabling-decorators

RussBaz commented 8 years ago

I am currently sick, so I would need some time to give it a proper review. Please expect me do this by the weekend or early next week.