Skip to content

How to add tooltip/docstring to a TypeAlias variable that is declared within if TYPE_CHECKING? #6317

Answered by erictraut
Daraan asked this question in Q&A
Discussion options

You must be logged in to vote

There is no formally accepted specification for attribute docstrings. The closest thing is PEP 258, which was submitted for consideration but ultimately rejected. This is the spec I used when implementing support for attribute docstrings in pyright. This PEP clearly states that string literals should be considered docstrings only if they're at the top level of a module or class definition, not within a conditional block. That makes sense if you think about it.

There have been several attempts over the past few years to formally specify ways to add docstrings to attributes and type aliases, but these attempts have faltered.

If you'd like to propose a standard in this area, the Python Ideas

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Daraan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants