So I'm interested in learning about data validation. Especially in Python.
Python all ready has several common idioms for data validation.
There are several statements that evaluate data. For instance, isinstance(object, classinfo) will check that the given object is an instance of the class or type in classinfo.
One idiom is that it is better to ask forgiveness than permission, which basically means it is better to try something and catch the errors instead of trying to force the data to be valid. The main language feature that supports this idiom is the try statement and its associated statements.
It can be very bulky to write. I wonder if it would be possible to write a function wrapper to simplify the writing of such a check or if such wrapper would be worth it or appropriate.
In addition, it can only catch general errors. Sometimes what is technically valid input is invalid input according to design specifications. Now I've read that there is a way for a user to create their own errors and exceptions. Now I don't know if this is true or not, but if it is that would seem the most natural thing to do.
However, another option might be to create custom data validation functions. I'm not talking about the poorly coded "if x != 1 and x != 2 and x != 3", but powerful yet general functions to ensure that data is valid.
Here's the Wikipedia entry for data validation.
What are your thoughts?