Contracts for modules¶
module_load allows you to control what can happen at module load stage.
deal.activate()before importing anything.
deal.module_load()in any place at module level in all modules that should be tested. Pass inside all contracts that should be controlled. By design, only contracts from deal without arguments are supported.
import deal deal.activate() from .other import something
import deal import something_else deal.module_load(deal.pure) something = 1 print(1) # contract violation! deal.SilentContractError will be raised
How it works¶
deal.activateregisters import finder and loader. From now, all imported files will be checked by deal.
The loader reads imported file, generates AST for it, and looks for
If loader found
deal.module_loadin the module, it extracts contracts from it.
If all contracts are valid (imported from deal and have no arguments), loader loads the module with contracts activated.