Checking function's parameters (type, value) or not ?

ast nomail at com.invalid
Wed Apr 6 09:07:14 EDT 2016


Hello

I would like to know if it is advised or not to test
a function's parameters before running it, e.g
for functions stored on a public library ?

Example:

def to_base(nber, base=16, use_af=True, sep=''):

    assert isinstance(nber, int) and nber >= 0
    assert isinstance(base, int) and base >= 2
    assert isinstance(use_af, bool)
    assert isinstance(sep, str) and len(sep) == 1

   tbc

With these tests, you are sure that the function to_base is
well used. But it slows down the program.
Without, python interpreter may crash later in the function
or worse provide a meaningless result.

What library designers do ?
    
 



More information about the Python-list mailing list