roboglia.utils.check_type

check_type(value, to_type, context, context_id, logger, message=None)[source]

Checks if a value is of a certain type and raises a customized exception message with better context.

Parameters
  • value (any) – a value to be checked

  • to_type (type) – the type to be checked against

  • context (str) – a string indicating the context of the check, for example ‘Bus’ or ‘Device’

  • context_id (str or int) – indicates the precise context (the name of the object or, in case the key we are searching is the name we will have to use the index of the item in the initialization dictionary)

  • logger (logger object) – where the logging will be written

  • message (str) – if this is provided the function will use this message for logging and raise instead of building a message specific for the context.

Raises

ValueError – if the value is not of the type indicated