-
Notifications
You must be signed in to change notification settings - Fork 6
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
How to differentiate class variables and instance variables? #30
Comments
For properly typed Python code, it would be derivable from the type being wrapped in Some way of describing in docspec whether a |
Yes we do distinct the class variable with the instances variables by doing AST analysis. You can check it out here: https://github.com/twisted/pydoctor/blob/master/pydoctor/astbuilder.py#L517
That's basically what we're doing, we also look for typing.ClassVar annotation, but they are not really common. Also, a class variable do not need to be annotated as such to be properly recognized by pydoctor. If we want to keep this outside of |
Hi, chiming in 🙂 |
👋 @pawamoy , thanks for your input as well. I think this is a reasonable request. I currently have something like this in mind of the @dataclasses.dataclass
class Data(ApiObject):
"""
Represents a variable assignment (e.g. for global variables (often used as constants) or class members).
"""
class Semantics(enum.Enum):
#: The #Data object represents an instance variable.
InstanceVariable = 0
#: The #Data object represents a class variable.
ClassVariable = 1
#: The #Data object represents a constant.
Constant = 2
#: The datatype associated with the assignment as code.
datatype: t.Optional[str] = None
#: The value of the variable as code.
value: t.Optional[str] = None
#: A list of hints about the semantics of the variable that this #Data object describes.
semantics: t.List[Semantics] = dataclasses.field(default_factory=list) What do you think @tristanlatr @pawamoy ? |
Looks good! |
Is there a way currently to differentiate the two ?
I was thinking of naming the instance variables
self.xxx
, but maybe you have something else in mind?Thanks
The text was updated successfully, but these errors were encountered: