RussBaz / enforce

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

Config Parameter "enable" is acting in the wrong scope #14

Closed TheDataLeek closed 7 years ago

TheDataLeek commented 8 years ago

See the wiki page: https://github.com/RussBaz/enforce/wiki/Configuration

In a nutshell, the built in functionality with wrapt lets us disable these checks and skip over them, however since this happens at the bytecode level it needs to occur right as the file is read.

This behavior isn't ideal, as we would like to be able to dynamically disable functions based on possibly arguments, or other things. This currently isn't possible...

This is a low priority issue, however we still need to keep track of it. (I'll try to get to it soon, but if someone beats me to it that would also be great.)

RussBaz commented 8 years ago

I think you should look at the 'Enforcer' object, especially at 'validate_inputs' and 'validate_outputs' methods. Each enforcer already contains unused properties 'settings' and 'enabled'. Settings property should point to the Config object, I think. It might be a good idea to skip validation in them if certain options are set.

Also, 'enabled' flag is used there separately to signify that it is intended as an override for the value in the settings. It might be useful in some cases for disabling proxy object type validation.

RussBaz commented 7 years ago

In one of the latest commits in the dev branch, I refactored settings in order to enable dynamic switching on and off of the individual 'enforcers' and as a part of the group. A global kill switch was also added to the settings.