validate_arg_type

(function from pyomo.contrib.pyros.uncertainty_sets)

pyomo.contrib.pyros.uncertainty_sets.validate_arg_type(arg_name, arg_val, valid_types, valid_type_desc=None, is_entry_of_arg=False, check_numeric_type_finite=True)[source]

Perform type validation of an argument to a function/method. If type is not valid, raise a TypeError with an appropriate message.

Parameters:
  • arg_name (str) – Name of argument to be displayed in exception message.

  • arg_val (object) – Value of argument to be checked.

  • valid_types (type or tuple of types) – Valid types for the argument value.

  • valid_type_desc (str or None, optional) – Description of valid types for the argument value; this description is included in the exception message.

  • is_entry_of_arg (bool, optional) – Is the argument value passed an entry of the argument described by arg_name (such as entry of an array or list). This will be indicated in the exception message. The default is False.

  • check_numeric_type_finite (bool, optional) – If the valid types comprise a sequence of numeric types, check that the argument value is finite (and also not NaN), as well. The default is True.

Raises:
  • TypeError – If the argument value is not a valid type.

  • ValueError – If the finiteness check on a numerical value returns a negative result.