Checker Reference¶
Core¶
is_type¶
-
is_type
(obj, type_)[source]¶ Indicate if
obj
is a type intype_
.Hint
This checker is particularly useful when you want to evaluate whether
obj
is of a particular type, but importing that type directly to use inisinstance()
would cause a circular import error.To use this checker in that kind of situation, you can instead pass the name of the type you want to check as a string in
type_
. The checker will evaluate it and see whetherobj
is of a type or inherits from a type whose name matches the string you passed.Parameters: Returns: True
ifobj
is a type intype_
. Otherwise,False
.Return type:
are_equivalent¶
-
are_equivalent
(*args)[source]¶ Indicate if arguments passed to this function are equivalent.
Hint
This checker operates recursively on the members contained within iterables and
dict
objects.Caution
If you only pass one argument to this checker - even if it is an iterable - the checker will always return
True
.To evaluate members of an iterable for equivalence, you should instead unpack the iterable into the function like so:
obj = [1, 1, 1, 2] result = are_equivalent(*obj) # Will return ``False`` by unpacking and evaluating the iterable's members result = are_equivalent(obj) # Will always return True
Parameters: args – One or more values, passed as positional arguments. Returns: True
ifargs
are equivalent, andFalse
if not.Return type: bool
are_dicts_equivalent¶
is_between¶
-
is_between
(value, minimum=None, maximum=None)[source]¶ Indicate whether
value
is greater than or equal to a suppliedminimum
and/or less than or equal tomaximum
.Note
This function works on any
value
that support comparison operators, whether they are numbers or not. Technically, this means thatvalue
,minimum
, ormaximum
need to implement the Python magic methods__lte__
and__gte__
.If
value
,minimum
, ormaximum
do not support comparison operators, they will raiseNotImplemented
.Parameters: - value (anything that supports comparison operators) – The
value
to check. - minimum (anything that supports comparison operators /
None
) – If supplied, will returnTrue
ifvalue
is greater than or equal to this value. - maximum (anything that supports comparison operators /
None
) – If supplied, will returnTrue
ifvalue
is less than or equal to this value.
Returns: True
ifvalue
is greater than or equal to a suppliedminimum
and less than or equal to a suppliedmaximum
. Otherwise, returnsFalse
.Return type: Raises: - NotImplemented – if
value
,minimum
, ormaximum
do not support comparison operators - ValueError – if both
minimum
andmaximum
areNone
- value (anything that supports comparison operators) – The
has_length¶
-
has_length
(value, minimum=None, maximum=None)[source]¶ Indicate whether
value
has a length greater than or equal to a suppliedminimum
and/or less than or equal tomaximum
.Note
This function works on any
value
that supports thelen()
operation. This means thatvalue
must implement the__len__
magic method.If
value
does not support length evaluation, the checker will raiseNotImplemented
.Parameters: - value (anything that supports length evaluation) – The
value
to check. - minimum (numeric) – If supplied, will return
True
ifvalue
is greater than or equal to this value. - maximum (numeric) – If supplied, will return
True
ifvalue
is less than or equal to this value.
Returns: True
ifvalue
has length greater than or equal to a suppliedminimum
and less than or equal to a suppliedmaximum
. Otherwise, returnsFalse
.Return type: Raises: - TypeError – if
value
does not support length evaluation - ValueError – if both
minimum
andmaximum
areNone
- value (anything that supports length evaluation) – The
is_dict¶
is_string¶
-
is_string
(value, coerce_value=False, minimum_length=None, maximum_length=None, whitespace_padding=False)[source]¶ Indicate whether
value
is a string.Parameters: - value – The value to evaluate.
- coerce_value (
bool
) – IfTrue
, will check whethervalue
can be coerced to a string if it is not already. Defaults toFalse
. - minimum_length (
int
) – If supplied, indicates the minimum number of characters needed to be valid. - maximum_length (
int
) – If supplied, indicates the minimum number of characters needed to be valid. - whitespace_padding (
bool
) – IfTrue
and the value is below theminimum_length
, pad the value with spaces. Defaults toFalse
.
Returns: True
ifvalue
is valid,False
if it is not.Return type:
is_iterable¶
-
is_iterable
(obj, forbid_literals=(<class 'str'>, <class 'bytes'>), minimum_length=None, maximum_length=None)[source]¶ Indicate whether
obj
is iterable.Parameters: - forbid_literals (iterable) – A collection of literals that will be considered invalid
even if they are (actually) iterable. Defaults to a
tuple
containingstr
andbytes
. - minimum_length (
int
) – If supplied, indicates the minimum number of members needed to be valid. - maximum_length (
int
) – If supplied, indicates the minimum number of members needed to be valid.
Returns: True
ifobj
is a valid iterable,False
if not.Return type: - forbid_literals (iterable) – A collection of literals that will be considered invalid
even if they are (actually) iterable. Defaults to a
is_not_empty¶
is_none¶
is_variable_name¶
-
is_variable_name
(value)[source]¶ Indicate whether
value
is a valid Python variable name.Caution
This function does NOT check whether the variable exists. It only checks that the
value
would work as a Python variable (or class, or function, etc.) name.Parameters: value – The value to evaluate. Returns: True
ifvalue
is valid,False
if it is not.Return type: bool
is_callable¶
Date / Time¶
is_date¶
is_datetime¶
is_time¶
is_timezone¶
-
is_timezone
(value, positive=True)[source]¶ Indicate whether
value
is atzinfo
.Caution
This does not validate whether the value is a timezone that actually exists, nor can it resolve timzone names (e.g.
'Eastern'
or'CET'
).For that kind of functionality, we recommend you utilize: pytz
Parameters: - value – The value to evaluate.
- positive (
bool
) – Indicates whether thevalue
is positive or negative (only has meaning ifvalue
is a string). Defaults toTrue
.
Returns: True
ifvalue
is valid,False
if it is not.Return type:
Numbers¶
is_numeric¶
-
is_numeric
(value, minimum=None, maximum=None)[source]¶ Indicate whether
value
is a numeric value.Parameters: - value – The value to evaluate.
- minimum (numeric) – If supplied, will make sure that
value
is greater than or equal to this value. - maximum (numeric) – If supplied, will make sure that
value
is less than or equal to this value.
Returns: True
ifvalue
is valid,False
if it is not.Return type:
is_integer¶
-
is_integer
(value, coerce_value=False, minimum=None, maximum=None, base=10)[source]¶ Indicate whether
value
contains a whole number.Parameters: - value – The value to evaluate.
- coerce_value (
bool
) – IfTrue
, will returnTrue
ifvalue
can be coerced to whole number. IfFalse
, will only returnTrue
ifvalue
is already a whole number (regardless of type). Defaults toFalse
. - minimum (numeric) – If supplied, will make sure that
value
is greater than or equal to this value. - maximum (numeric) – If supplied, will make sure that
value
is less than or equal to this value. - base (
int
) – Indicates the base that is used to determine the integer value. The allowed values are 0 and 2–36. Base-2, -8, and -16 literals can be optionally prefixed with0b/0B
,0o/0O/0
, or0x/0X
, as with integer literals in code. Base 0 means to interpret the string exactly as an integer literal, so that the actual base is 2, 8, 10, or 16. Defaults to10
.
Returns: True
ifvalue
is valid,False
if it is not.Return type:
is_float¶
-
is_float
(value, minimum=None, maximum=None)[source]¶ Indicate whether
value
is afloat
.Parameters: - value – The value to evaluate.
- minimum (numeric) – If supplied, will make sure that
value
is greater than or equal to this value. - maximum (numeric) – If supplied, will make sure that
value
is less than or equal to this value.
Returns: True
ifvalue
is valid,False
if it is not.Return type:
is_fraction¶
-
is_fraction
(value, minimum=None, maximum=None)[source]¶ Indicate whether
value
is aFraction
.Parameters: - value – The value to evaluate.
- minimum (numeric) – If supplied, will make sure that
value
is greater than or equal to this value. - maximum (numeric) – If supplied, will make sure that
value
is less than or equal to this value.
Returns: True
ifvalue
is valid,False
if it is not.Return type:
is_decimal¶
-
is_decimal
(value, minimum=None, maximum=None)[source]¶ Indicate whether
value
contains aDecimal
.Parameters: - value – The value to evaluate.
- minimum (numeric) – If supplied, will make sure that
value
is greater than or equal to this value. - maximum (numeric) – If supplied, will make sure that
value
is less than or equal to this value.
Returns: True
ifvalue
is valid,False
if it is not.Return type: