[Biopython-dev] checker_function for the options in bio.application.abstractCommandline

Bartek Wilczynski bartek at rezolwenta.eu.org
Fri Jul 18 12:45:02 EDT 2003


I think, there's something not exactly consistent about the parameter setting in
AbstractCommandline class. The problem i see is the following code in the
set_parameter method:

   if parameter.checker_function is not None:

   parameter.value = value

if we put it together with the documentation of a checker_function:

    o checker_function -- a reference to a function that will determine
    if a given value is valid for this parameter.

it is at least confusing.

I'm not sure, whether the author meant checker_function to raise an exception when
the parameter is not valid, or he just forgot to put the value assignement into
another if-then statement with the result of checker_function as condition, but
I would really appreciate if someone made it more clear.

I would rather opt for the if-then statement, because it allows me to write
simple and self-explanatory checker functions like 

lambda x : isinstance(x,int)

and not to bother with raising the exception. the code in the set_parameter
could look then like:

if parameter.checker_function is not None:
  if paramater.checker_function(value):
    parameter.value = value
    raise ValueError("Invalid parameter value " + repr(value) + " for parameter
" + name)

   Bartek Wilczyñski

More information about the Biopython-dev mailing list