def infer_type()

in modules/python/kusto/generate_commands.py [0:0]


def infer_type(value):
    # Check if it's a boolean
    if isinstance(value, str) and value.lower() in ['true', 'false']:
        return "bool"

    # Check if it's an integer
    try:
        int(value)
        return "real"
    except (ValueError, TypeError):
        pass

    # Check if it's a float
    try:
        float(value)
        return "real"
    except (ValueError, TypeError):
        pass

    # Check if it's dynamic
    if isinstance(value, (dict, list)):
        return "dynamic"

    # Attempt to load the string as JSON
    try:
        parsed_json = json.loads(str(value))
        if isinstance(parsed_json, (dict, list)):
            return "dynamic"
    except (json.JSONDecodeError, TypeError):
        pass

    # Check if it's a datetime
    try:
        isoparse(value)
        return "datetime"
    except ValueError:
        pass

    # If none of the above, take it as string
    return "string"