-
Let's say that I have a from typing import NamedTuple
class LogItem(NamedTuple):
"""Represents a log item"""
message: str
"""The message sent"""
response: str
"""The response received""" And when I hover over the fields, the documentation string given shows up, which is extremely useful. However, in Python itself, I don't know how to access the documentation strings for the fields. For example: >>> LogItem.__doc__
'Represents a log item'
>>> LogItem.message.__doc__
'Alias for field number 0' How is Pyright getting the documentation string? Is it using a super custom parser, or is there a simple method that I could use in pure Python to get each field's documentation string? If dataclasses are an alternative for this, I'd be open to that as well. Thank you for any help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Pyright implements its own parser (written in TypeScript). I don't think the CPython parser retains variable docstrings in the AST it produces. @JelleZijlstra could probably confirm. |
Beta Was this translation helpful? Give feedback.
Pyright implements its own parser (written in TypeScript). I don't think the CPython parser retains variable docstrings in the AST it produces. @JelleZijlstra could probably confirm.