From 0e9bfbcc8620b3c0ffb0f3b03fed08d381e14c4d Mon Sep 17 00:00:00 2001 From: Fabio Caccamo Date: Thu, 30 Jan 2020 15:27:39 +0100 Subject: [PATCH] Added benedict.utils.type_util. --- benedict/utils/type_util.py | 74 +++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 benedict/utils/type_util.py diff --git a/benedict/utils/type_util.py b/benedict/utils/type_util.py new file mode 100644 index 0000000..a6fb106 --- /dev/null +++ b/benedict/utils/type_util.py @@ -0,0 +1,74 @@ +# -*- coding: utf-8 -*- + +from datetime import datetime +from decimal import Decimal +from six import binary_type, integer_types, string_types + + +def is_binary(val): + return isinstance(val, binary_type) + + +def is_bool(val): + return isinstance(val, bool) + + +def is_collection(val): + return isinstance(val, (dict, list, set, tuple, )) + + +def is_datetime(val): + return isinstance(val, datetime) + + +def is_decimal(val): + return isinstance(val, Decimal) + + +def is_dict(val): + return isinstance(val, dict) + + +def is_dict_or_list(val): + return isinstance(val, (dict, list, )) + + +def is_float(val): + return isinstance(val, float) + + +# def is_function(val): +# return callable(val) + + +def is_integer(val): + return isinstance(val, integer_types) + + +def is_json_serializable(val): + json_types = (bool, dict, float, ) + integer_types + \ + (list, tuple, set, ) + string_types + return isinstance(val, json_types) + + +def is_list(val): + return isinstance(val, list) + + +def is_list_or_tuple(val): + return isinstance(val, (list, tuple, )) + + +def is_none(val): + return val is None + +# def is_set(val): +# return isinstance(val, set) + + +def is_string(val): + return isinstance(val, string_types) + + +# def is_tuple(val): +# return isinstance(val, tuple)