Docstrings for new type aliases as defined in PEP 695

As Jelle said, there is currently no standardized way to provide documentation for type aliases.

There is a draft PEP 727 that proposed to add such support, but the latest version of the PEP removes the support for type alias doc strings. Plus, there’s a lot of community pushback on this PEP, so its future is unclear.

That said, pyright (which is presumably what you’re using to power your editor experience) currently supports the convention of interpreting multi-line strings below a type alias definition as a doc string. It would make sense to extend that support to type statements. I just didn’t think to add this when I added support for PEP 695. I’ve added this enhancement request in the pyright issue tracker.

I’ll note that this isn’t currently standardized, so other type checkers, language servers, and static analysis tools may not honor this.

1 Like