I'm using zope.interface
module to declare an interface with some methods and attributes. Also, cannot I somehow declare not only the attribute names, but also their types?
from zope.interface import Interface, Attribute, implementer, verify
class IVehicle(Interface):
"""Any moving thing"""
speed = Attribute("""Movement speed""") #CANNOT I DECLARE ITS TYPE HERE?
def move():
"""Make a single step"""
pass
You can restrict the type of the attribute by introducing an
invariant
.your
IVehicle
class has avalidateInvariants
method you can call to validate none of the invariants are being broken in classes that implement it.I don't know of a way to specify the type of the Attribute directly, though.