Home | Trees | Indices | Help |
---|
|
object --+ | basevalidator.BaseValidator --+ | ToType
Convert a value to a given type.
This is largely syntactic sugar: It will actually accept any callable as an argument, but is intended for use with class constructors. You could use raw types and classes, but this throws much nicer error messages. Conversion is done by simply passing a value to the parameter callable.
|
|||
|
|||
|
|||
|
|||
Inherited from Inherited from |
|
|||
Inherited from |
|
Class c'tor, accepting a type. For example: >>> v = ToType(int, type_name='an integer') >>> v(1) 1 >>> v(2.3) 2 >>> v('foo') Traceback (most recent call last): ... ValueError: can't convert 'foo' to an integer >>> v = ToType(float) >>> v('foo') Traceback (most recent call last): ... ValueError: can't convert 'foo' to float
|
|
Transform a value to the desired form. This is the workhorse method that is called by convert to transform passed values. As such, errors are signalled by throwing a meaningful exception. This is one of the obvious and easiest places to customize behaviour by overriding in a subclass.
|
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Fri Jul 22 15:13:46 2011 | http://epydoc.sourceforge.net |