def get_module_name(module):
    """Returns a module's name or None if one cannot be found.
    Relevant PEP: https://www.python.org/dev/peps/pep-0451/
    """
    if hasattr(module, '__spec__'):
        return module.__spec__.name
    return getattr(module, '__name__', None)