The SingleState base class provides a common superclass for State classes that can only validate a single API function call, such as Command and Error.
It inherits from the State base class and extends the protocol defined there in the following way:
-
Subclasses of
SingleStateare recommended to define an__init__method that takes at least two parameters, the second of which is optional.The first parameter will be a
function-type object; this is the object that must be passed as the second parameter of__call__if validation is to succeed. It is recommended that this object is stored in the instance'sapi_funcattribute.The second parameter will be an iterable. This represents the arguments that must be passed to the API call if validation is to succeed. It is recommended that this object is stored in the instance's
argsattribute.This second parameter should default to an empty iterator, indicating that the API function call takes no arguments.
-
If the recommended storage strategy outlined in the above item has been followed, it is not necessary for subclasses of
SingleStateto define an__eq__or__ne__method.SingleStateprovides a default implementation of__eq__that follows the above strategy.In this default implementation, the objects'
api_funcattributes will be compared withisand theirargsattributes with==. -
Subclasses of
SingleStateneed not define a__len__method;SingleStatedefines a__len__implementation that always returns 1, which should be suitable for most, if not all, subclasses. -
Subclasses of
SingleStateneed not define aresetmethod.SingleStateprovides a default implementation that simplypasses, which should be sufficient for most, if not all, subclasses.
Note that if the protocol outlined above does not meet your needs, you should probably consider subclassing State directly.