-
Notifications
You must be signed in to change notification settings - Fork 20
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
feat: type annotations for @properties #284
Comments
Thanks for raising, it seems like the renderer has everything it needs to render annotation types, but it's a bit tricky to figure out these aspects of generating attributes:
As a result, quartodoc handles attributes using these behaviors:
Minimal reproducible exampleDoes this look like I'm reproducing the situation? test_func.py class Table:
@property
def x(self) -> int:
"""The x attribute"""
return 1 rendering doc from quartodoc import Auto, blueprint, MdRenderer
bp = blueprint(Auto(name = "test_func.Table"))
print(MdRenderer().render(bp))
Fixing this particular issue in ibisOption 1: add attributes sectionWDYT of adding an attributes section to your docstring for now? It currently, requires repeating the description (will open issue upstream in griffe), but does fetch the type info automatically from the property. Here's an example class Table:
"""
Attributes
----------
x
The x attribute
"""
@property
def x(self) -> int:
"""The x attribute"""
return 1 Option 2: document attributes more like they're methodsIn this case, we'd have the attributes summary link to a fully rendered docstring for each attribute, as if they're methods. If this seems like a better option, let me know. I think we'd need to add an option to enable this style of documentation on classes / modules. |
Thanks for the detailed explanation!
Yes I think you have it. Whatever the rendered output, I want it to come from the logic of
Then, once we have the list of annotations, we need to choose how to render them. My ideal would be
CC @cpcloud @lostmygithubaccount @jcrist @gforsyth if they have any opinions |
Thanks for weighing in, this is super helpful. The suggestion on rendering makes a lot of sense. Just to recap, it sounds like the option to render like methods (let's say
WDYT of that approach? (I'd lean on punting on any automated toggling between behaviors for now, but it seems useful to implement down the road, based on whether attribute docs are one-liners). Minor detail on documenting attributes
You should be able to document any class attribute, even a dynamically created one, using this syntax: class SomeClass:
x: int
"""The x value-less variable, whose value might be set on instantiation""" |
That sounds good! Instead of a true/false though for the option, I would name it something like Honestly if you really want to kick the ball down the road, if you just implemented the I agree that automated choosing can happen later.
Oh yeah, that's great, thanks for pointing that out! |
My recommendation (which is not documented anywhere yet) is to always document each attribute and property separately. Attributes sections in the parent docstring shouldn't be preferred, as they can just be generated automatically by iterating over the attributes to pick up their summary and type. Since each attribute has a full docstring, it can have its own heading+permalink+toc entry, and generated tables can link to it. As stated by @machow, even dynamic attributes can be given a docstring thanks to this syntax: class A:
attr_a: int
"""Docstring."""
# or even in the __init__ method
def __init__(self):
self.attr_b: float
"""Docstring.""" |
Thanks for all your work on this project!
Per a review comment in Ibis: ibis-project/ibis#7279 (comment)
A
@property
of a class is rendered without the type hint:It would be nice if it WAS rendered with a type hint. IDK if this is already a feature of non-property attributes...
The text was updated successfully, but these errors were encountered: