Propagate PEP 258 Attribute Docstrings to dataclass constructor and TypedDict keys #3120
Replies: 2 comments
-
Okay so it seems that if you trigger "Show Definition Preview Hover" or just "Show Hover" (they're different commands), then you do get something useful. And it works with both |
Beta Was this translation helpful? Give feedback.
-
Just to emphasize, as per #4759 , it does not actually show the docstring inside the main class constructor call, but instead, on the field-by-field level, meaning you must first choose to write a keyword argument to see the docstring for those fields. It would be nice if Pylance could add the docstring to the class docstring too if there is not already one there |
Beta Was this translation helpful? Give feedback.
-
Dataclasses
Currently, we can use the PEP 258 attribute docstring syntax to document dataclass fields, and it correctly shows up when we try to access these fields:

However when we try to construct such an object, we don't get the same parameter description, even though it refers to the same field, so could have the same description:

TypedDict
Similarly,
TypedDict
uses the class syntax, so we can use the docstring syntax again. And again, it doesn't show up in the constructor, or in a dictionary literal with the appropriate type:As with dataclasses, it would be very helpful to users for this information to be propagated to the constructor and/or dictionary literal.
Beta Was this translation helpful? Give feedback.
All reactions