-
-
Notifications
You must be signed in to change notification settings - Fork 194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dataclass member documentation issues #411
Comments
Hi there!
What would you have expected to happen? From pdoc's perspective (and from Python's perspective) there is no real distinction between instance and class variables, so they all display the same. You can document you intent by using
I think this refers to an unrelated issue, namely the rules by which we pick up elements to document. Right now pdoc does not document variables if they only have an annotation but neither a docstring nor a default value (refs #280). I'm open to changes here. I'm not sure if it makes more sense to unconditionally display members in lieu of a docstring (nudging maintainers to add one), or to only display members if they have a docstring. |
I'm expecting that the instance variables of a
This is totally fine by me, if someone wishes to document a variable without a default value, they should explicitly specify a docstring, it's the (overzealous) documentation of variables that do have default values (but no docstrings) I have an issue with. The adage "Explicit is better than implicit" should apply in this case IMHO. Side note: perhaps a new CLI option like |
To clarify: You mean once as part of the constructor and once as a variable? |
Yes. |
Any updates on this? |
Fixed in #436! |
Problem Description
When using the
@dataclass
decorator from thedataclasses
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:
Generating the documentation gives:
Note that neither
n
norm
should be shown in the docs forExample
(unless they have docstrings attached, as per the docs), whileasdf
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 accessasdf
).System Information
The text was updated successfully, but these errors were encountered: