def calc_parent_name(module_name, member_name=None):
    """Determine the 'parent' of a given dotted module name and (optional)
    member name.

    The idea is that ``getattr(parent_obj, final_attr)`` will equal
    get_named_object(module_name, member_name).

    :return: (module_name, member_name, final_attr) tuple.
    """
    if member_name is not None:
        split_name = member_name.rsplit('.', 1)
        if len(split_name) == 1:
            return module_name, None, member_name
        else:
            return module_name, split_name[0], split_name[1]
    else:
        split_name = module_name.rsplit('.', 1)
        if len(split_name) == 1:
            raise AssertionError('No parent object for top-level module %r' %
                (module_name,))
        else:
            return split_name[0], None, split_name[1]
