def isnamedtuple(x):
    """
    Utility to check whether something is a named tuple
    Since a namedtuple is basically a tuple with some additional metadata, we can't just do an `isinstance` check
    Based on https://stackoverflow.com/questions/2166818/how-to-check-if-an-object-is-an-instance-of-a-namedtuple/2166841#2166841
    """
    t = type(x)
    b = t.__bases__

    # Named tuples are tuple subclasses
    if len(b) != 1 or b[0] != tuple:
        return False

    # They have a fields tuple
    f = getattr(t, "_fields", None)
    if not isinstance(f, tuple):
        return False

    # All the items in the fields tuple are strings
    return all(type(n) == str for n in f)