[Tutor] help with a class

Alan Gauld alan.gauld at btinternet.com
Wed Aug 24 23:37:13 CEST 2011


On 24/08/11 21:03, Prasad, Ramit wrote:
> I was under the impression that asserts are more for testing
 > than for production code

That's true.

> def overide_options(self, options, run_id=None):
>
>          if not isinstance(options, dict):
>                  raise TypeError("override options requires a dict")

This is good if you want to keep the check in for production.
But using an assert here while testing then removing it from production 
would be a valid use too. The typecheck is not required for the function 
to work if you are confident of the data being passed in. assert checks 
the data while you are gaining that confidence.

So either approach is valid.
It all depends on how variable your input data is going to be.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list