Dataclass member documentation issues
See original GitHub issueProblem Description
When using the @dataclass
decorator from the dataclasses
module, pdoc seems to think that member (instance) variables with default values are actually class variables.
Furthermore, when using the typing.ClassVar
hint, the class variable is not picked up by the parser (unless it has a default, but apparently specifying a default isn’t a requirement for the code to run).
Steps to reproduce the behavior:
A minimal example is provided below:
from dataclasses import dataclass
from typing import ClassVar
@dataclass
class Example:
value: float
n: int = 1
m: int = 2
asdf: ClassVar
class OldExample:
n: int = 2
m: int = 2
asdf: ClassVar
def __init__(self):
pass
Generating the documentation gives:
Note that neither n
nor m
should be shown in the docs for Example
(unless they have docstrings attached, as per the docs), while asdf
should always be shown in the docs as it is a class variable (as specified by its type hint), even if it has no value assigned (the code runs fine as long as one doesn’t try to access asdf
).
System Information
pdoc: 12.0.2
Python: 3.9.13
Platform: Linux-5.16.0-1-amd64-x86_64-with-glibc2.33
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:6 (3 by maintainers)
Top GitHub Comments
Fixed in #436!
Any updates on this?