GeoEco.Metadata.ClassMetadata.ValidateMethodInvocation
- ClassMetadata.ValidateMethodInvocation()
Validates a classmethod’s or instance method’s arguments using the method’s
MethodMetadata.This method is intended to be called from the top of a classmethod or instance method to which a
MethodMetadatahas been added. Do not call it from static methods; at this time a validation function for static methods has not been implemented.Before performing any validation, this method initializes the calling method’s dependencies, if any are specified in the method’s metadata. If any
Dependencyinitializer raises an exception, it will bubble up and validation will fail. Assuming all dependencies succeed, this method then validates each of the calling method’s arguments by calling theValidateValue()method of theTypeMetadataobtained fromArgumentMetadata.Typefor the argument.ValidateValue()raises an exception if the specified value does not pass whatever checks are implemented by theTypeMetadata. For example:from GeoEco.Internationalization import _ import GeoEco.Metadata import GeoEco.Types class MyClass(object): @classmethod def IncrementInteger(cls, value): self.__doc__.Obj.ValidateMethodInvocation() return value + 1 GeoEco.Metadata.AddModuleMetadata(shortDescription=_('This is my example module.')) GeoEco.Metadata.AddClassMetadata(MyClass, shortDescription=_('This is my example class.')) GeoEco.Metadata.AddMethodMetadata(MyClass.IncrementInteger, shortDescription=_('Increments the specified integer.')) GeoEco.Metadata.AddArgumentMetadata(MyClass.IncrementInteger, 'cls', typeMetadata=GeoEco.Types.PythonClassorClassInstance(cls=MyClass), description=_(':class:`%s` or an instance of it.') % MyClass.__name__) GeoEco.Metadata.AddArgumentMetadata(MyClass.IncrementInteger, 'value', typeMetadata=GeoEco.Types.IntegerTypeMetadata(), description=_('Integer to increment.')) GeoEco.Metadata.AddResultMetadata(MyClass.IncrementInteger, 'newValue', typeMetadata=GeoEco.Types.IntegerTypeMetadata(), description=_('Incremented integer.')) x = MyClass.IncrementInteger(1) # This will succeed y = MyClass.IncrementInteger('a') # 'a' is not an int; ValidateMethodInvocation will raise TypeErrorAfter each argument is validated, this method examines the argument’s metadata to determine if the argument has any dependencies. If it does, this method then checks the metadata to see if the argument value requires the dependencies to be initialized, and if so, initializes them. (By default, if the argument is something other than
None, the dependencies will be initialized. This behavior may be overridden for by subclasses ofTypeMetadata.)