TypeChecker Class

class kwhelp.checks.TypeChecker(*args: type, **kwargs)[source]

Class that validates args match a given type

__init__(*args: type, **kwargs)[source]

Constructor

Other Arguments:

args (type): One or more types used for Validation purposes.

Keyword Arguments
  • raise_error (bool, optional) – If True then an error will be raised if a validate() fails: Othwewise validate() will return a boolean value indicationg success or failure. Default True

  • type_instance_check (bool, optional) – If True then validate() args are tested also for isinstance if type does not match, rather then just type check if type is a match. If False then values willl only be tested as type. Default True

validate(*args, **kwargs) bool[source]

Validates all *args and all **kwargs against types that are passed into constructor.

Returns

True if all *args and all **kwarg match a type; Otherwise; False.

Return type

bool

Raises

TypeError – if raise_error is True and validation fails.

property raise_error: bool

Determines if errors will be raised during validation

If True then errors will be raised when validation fails.

Getter

Gets if errors can be raised.

Setter

Sets if errors can be raised.

property type_instance_check: bool

Determines if instance checking is done with type checking.

If True then validate`() args are tested also for isinstance if type does not match, rather then just type check if type is a match. If False then values willl only be tested as type.

Getter

Gets type_instance_check value

Setter

Sets type_instance_check value

property types: Tuple[type]

Gets the types passed into constructor that are used for validating args