# Docstrings for new type aliases as defined in PEP 695

**URL:** <https://discuss.python.org/t/docstrings-for-new-type-aliases-as-defined-in-pep-695/39816>\
**Category:** Typing\
**Tags:** documentation\
**Created:** [November 28, 2023, 6:33pm UTC](https://discuss.python.org/t/docstrings-for-new-type-aliases-as-defined-in-pep-695/39816 "2023-11-28T18:33:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stausssi](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/stausssi/32/16132_2.png) [@Stausssi](https://discuss.python.org/u/Stausssi)\
**Post date:** [November 28, 2023, 6:33pm UTC](https://discuss.python.org/t/docstrings-for-new-type-aliases-as-defined-in-pep-695/39816/1 "2023-11-28T18:33:13Z")

</div>

Today I’ve started updating to Python 3.12 and adapted my code base to use the new typing aliases defined in PEP 695.  
Previously, my type was defined as `CustomType = dict[str, int]` with a docstring below using multine strings.  
Using the new type alias syntax, this was converted to `type CustomType = dict[str, int]`. I’ve then discovered that both pylint complains about the following multiline (doc)string (`pointless-string-statement`, also filed an [issue](https://github.com/pylint-dev/pylint/issues/9268)) and my editor (VS Code) does not display the docstring on hover.  
I’ve then went ahead and tried multiple different ways of adding a docstring (single line string above/below, `#:` comment above / below, regular comment above / below) but none of them worked.

How do I properly document my type aliases using the new syntax?

---

<div class="post-metadata">

**Author:** ![bmitc](https://avatars.discourse-cdn.com/v4/letter/b/46a35a/32.png) [@bmitc](https://discuss.python.org/u/bmitc)\
**Post date:** [December 3, 2023, 11:17pm UTC](https://discuss.python.org/t/docstrings-for-new-type-aliases-as-defined-in-pep-695/39816/2 "2023-12-03T23:17:13Z")

</div>

I have the exact same question, as asked on StackOverflow today: [How do I document a type alias defined using `type` in Python? - Stack Overflow](https://stackoverflow.com/questions/77596284/how-do-i-document-a-type-alias-defined-using-type-in-python)

Since the PEP doesn’t mention it, it doesn’t seem promising that support was added for this, which is unfortunate if that’s the case.

---

<div class="post-metadata">

**Author:** ![Jelle](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/jelle/32/1049_2.png) [@Jelle](https://discuss.python.org/u/Jelle)\
**Post date:** [December 4, 2023, 8:58pm UTC](https://discuss.python.org/t/docstrings-for-new-type-aliases-as-defined-in-pep-695/39816/3 "2023-12-04T20:58:47Z")

</div>

Docstrings for assignments aren’t part of the standard Python syntax; support in tools like Sphinx is just a convention. I would recommend tools apply the same convention to the `type` statement that they apply to existing old-style alias definitions.

---

<div class="post-metadata">

**Author:** ![erictraut](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/erictraut/32/15190_2.png) [@erictraut](https://discuss.python.org/u/erictraut)\
**Post date:** [December 4, 2023, 9:00pm UTC](https://discuss.python.org/t/docstrings-for-new-type-aliases-as-defined-in-pep-695/39816/4 "2023-12-04T21:00:09Z")

</div>

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

There is a draft [PEP 727](https://discuss.python.org/t/pep-727-documentation-metadata-in-typing) 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](https://github.com/microsoft/pyright/issues/6647) 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.

---

<div class="post-metadata">

**Author:** ![erictraut](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/erictraut/32/15190_2.png) [@erictraut](https://discuss.python.org/u/erictraut)\
**Post date:** [December 5, 2023, 1:05am UTC](https://discuss.python.org/t/docstrings-for-new-type-aliases-as-defined-in-pep-695/39816/5 "2023-12-05T01:05:42Z")

</div>

I’ve added support for `type` statement doc strings within pyright. It will be included in the next pyright release. It will also be in a future release of Pylance, the default Python language server for VS Code.

---

<div class="post-metadata">

**Author:** ![Stausssi](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/stausssi/32/16132_2.png) [@Stausssi](https://discuss.python.org/u/Stausssi)\
**Post date:** [December 6, 2023, 2:25pm UTC](https://discuss.python.org/t/docstrings-for-new-type-aliases-as-defined-in-pep-695/39816/6 "2023-12-06T14:25:53Z")

</div>

Understood, thanks for your answers and the quick fix for pyright / pylance. I’ll forward this information to the tools I’ve encountered issues with.
