Class-like syntax for union type aliases and natural docstrings

To elaborate a bit on this, with PEP 846 we would indeed be able to write

type SourceObject = (
    ModuleType
    | type[Any]
    | MethodType
    | FunctionType
    | TracebackType
    | FrameType
    | CodeType
    | Callable[..., Any]
)
"""Objects whose source inspect.getsource() and friends can retrieve."""

which to me looks like a very reasonable alternative to the proposed

There’s now also a discourse thread for this PEP draft: PEP 846: Docstrings for Type Aliases

2 Likes