3.1.7.1. c3po.raises.checkScope module
Contain the meta-class CheckScopeMeta and class wrapper checkScope().
- class c3po.raises.checkScope.CheckScopeMeta(name, bases, dct)
Bases:
typeMetaclass related to the use of
checkScope().- static __new__(cls, name, bases, dct)
- c3po.raises.checkScope.checkScope(baseclass)
Add a verification of the calling context of ICoCo methods.
checkScope()is to be applied on a class (not an object) and return a new class that inherits from the provided one.checkScope()has the following effects:It raises
icoco.exception.WrongContexterrors when an ICoCo method is called in a wrong context (see ICoCo documentation).It adds an object attribute ‘problemName’ used in the message of these
icoco.exception.WrongContexterrors. Default:f"{self.__class__.__module__}.{self.__class__.__name__}”It also adds the object attribute ‘iCoCoEnsureScope’ that can be used to activate / desactivate these checks. Default:
iCoCoEnsureScope=Truewhich means activated.
Two additional object attributes are added for internal use:
_iCoCoInitializedand_iCoCoTimeStepDefined.checkScope()can be used either as a python decorator (where the class is defined) in order to modify the class definition everywhere:@c3po.raises.checkScope class MyClass(...): ...
or it can be used in order to redefined only locally the class like that:
MyNewClass = c3po.raises.checkScope(MyClass)
Note
checkScope()looks for ICoCo methods definitions in base classes in order to overload them.checkScope()relies on a metaclass (c3po.raises.checkScope.CheckScopeMeta). That means that daughter classes will also be modified bycheckScope().Warning
It is recommended not to overload a class: use “
MyNewClass = c3po.raises.checkScope(MyClass)” and not “MyClass = c3po.raises.checkScope(MyClass)”. Overloading a class may lead toTypeError, in particular in case of inheritance, if the mother class is not accessible any more.- Parameters:
baseclass – The class to modify.
- Return type:
A new class, with modified methods.