Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if not self.enabled:
return cls
assert self._contract is not None, "self._contract must be set if the contract was enabled."
if not hasattr(cls, "__invariants__"):
invariants = [] # type: List[Contract]
setattr(cls, "__invariants__", invariants)
else:
invariants = getattr(cls, "__invariants__")
assert isinstance(invariants, list), \
"Expected invariants of class {} to be a list, but got: {}".format(cls, type(invariants))
invariants.append(self._contract)
icontract._checkers.add_invariant_checks(cls=cls)
return cls
def __new__(mlcs, name, bases, namespace, **kwargs): # type: ignore
"""Create a class with inherited preconditions, postconditions and invariants."""
_dbc_decorate_namespace(bases, namespace)
cls = super().__new__(mlcs, name, bases, namespace, **kwargs) # type: ignore
if hasattr(cls, "__invariants__"):
icontract._checkers.add_invariant_checks(cls=cls)
return cls