from typing import Optional
from typing import List
from typing import Any


def visiblename(
    name: str, all_things: Optional[List[str]] = None, obj: Optional[Any] = None
) -> bool:
    """Decide whether to show documentation on a variable."""
    # Certain special names are redundant or internal.
    # XXX Remove __initializing__?
    if name in {
        # people use these for all sorts of things
        # "__author__",
        # "__credits__",
        # "__date__",
        # "__version__",
        #
        # These are internal implementation details USUALLY
        "__builtins__",
        "__cached__",
        "__doc__",
        "__file__",
        "__spec__",
        "__loader__",
        "__module__",
        "__name__",
        "__package__",
        "__path__",
        "__qualname__",
        "__slots__",
        "__dict__",
        "__weakref__",
    }:
        return False
    # Private names are hidden, but special names are displayed.
    if name.startswith("__") and name.endswith("__"):
        return True
    # Namedtuples have public fields and methods with a single leading underscore
    if name.startswith("_") and hasattr(obj, "_fields"):
        return True
    if all_things is not None:
        # only document that which the programmer exported in __all__
        return name in all_things
    return not name.startswith("_")