Determine whether element conforms to etype

def element_conforms(element, etype) -> bool:
    """ Determine whether element conforms to etype"""
    from pyjsg.jsglib import Empty

    if isinstance(element, etype):
        return True
    # This catches the Optional[] idiom
    if (element is None or element is Empty) and issubclass(etype, type(None)):
        return True
    elif element is Empty:
        return False
    elif isinstance(etype, type(type)) and (issubclass(etype, type(None))):
        return element is None
    elif element is None:
        return False
    else:
        return isinstance(element, etype)