-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Using a colon in the property's description, treats the leading text as return type #9273
Comments
It seems you're using the napoleon module. So you should use numpydoc style or google style docstring. But your docstring does not match either. |
I don't get it. I know I'm using napoleon, but even then, each docstring starts with a description - what do you mean "does not match either"? Are the headers like This issue appears only for properties, functions and class description work fine: This is a bug in the napoleon module, which incorrectly considers everything before the colon as the return type. |
If my understanding correct, Google style recommends to describe the attributes and properties of the class at the "Attribute" section of the class docstring: https://numpydoc.readthedocs.io/en/latest/format.html#documenting-classes Note: Numpydoc style is also: https://numpydoc.readthedocs.io/en/latest/format.html#documenting-classes BTW, I found the reason why the napoleon extension considers the leading text before colon as a type. I guess this is an originated behavior of napoleon, not a bug. (But I feel this is against the style...) |
Well, this is quite a bit inconsistent then, as you can see. Also impossible to avoid too, it seems - I tried "escaping" the colon character, but nothing worked. How do I add a description containing a colon to a property now? |
I thought about using
Still, I feel it's quite inconsistent. It'd be nice to have a way to escape the colon, or some other way of telling napoleon that this is part of a description, not documentation syntax. |
I'm having the same issue. Example code 1: def is_thing(self) -> bool:
"""Determines if this expression is the built in class owl:Thing.
Returns:
True if this expression is owl:Thing
""" The result looks like:
Since I'm using type annotations, I do not want to specify the type. Example code 2: Thing: Final = make_thing() #: The OWL Class corresponding to owl:Thing The result looks like
Can I escape the colon somehow? |
@ailin-nemui Your best bet is to use |
Hello, I share your point of view in the sense that we should be able to use a commas in the first line of a free form description of an attribute/property. It’s currently impossible because the Napoleon (this version) do not have the concept of what’s a valid type specification and what’s not. My proposal to solve this issue is similar to what I proposed in #7077, meaning, checking if the string before the column is a valid type, if so, then we consider it as the type, if not, it’s simply part of the description. For the implementation part, I link here a version of Napoleon extension that wraps the type specification inside a new object: TypeDocstring and provides a manner to check wether a string is a valid type: https://github.com/tristanlatr/pydoctor/blob/6b3f23b791704ef2639bfa0b2d9d9efb0e621c78/pydoctor/napoleon/docstring.py#L91 Review the tests for the type specification here: https://github.com/tristanlatr/pydoctor/blob/6b3f23b791704ef2639bfa0b2d9d9efb0e621c78/pydoctor/test/test_napoleon_docstring.py#L84 Tell me what you think. Thanks |
@DevilXD and @ailin-nemui i had the same problem and fixed it by adding : before the description as below:
|
I ran into this in a way that I didn't expect at all. The docstring is """Date and time of the collection in UTC (YYYY-MM-DDTHH:MM:SS)""" and it rendered this: Beyond the fact that this is obviously wrong, I didn't know something could have multiple types. Because it has multiple types, adding the type annotation to the docstring doesn't fix anything, it just adds the correct type to the top of the list. There are two workarounds that I've found.
|
Nevermind, I checked the docstring outside of a EDIT: With this minimal example: class HH: pass
class MM: pass
class SS: pass
class A:
@property
def a(self):
"""List of HH:MM:SS strings."
return [] we have no way to understand that
would render without a type. |
Yeah, I tried something like that at first, but using |
Actually, it was not a fix for you. It was an example of what would be ideal in the best world xD |
…perly (#4535) Fix: Pi-Squared-Inc/pi2#1644 Unfortunately, Napoleon extensions can't escape `:` and treat everything before it as a type thus, the rendering of this example was outputting a wrong and malformed description of the function as shown below:  As this isn't a key feature description, we chose to remove it to get cleaner documentation:  This is a known issue discussed here: sphinx-doc/sphinx#9273
Describe the bug
Using a colon in the property's description, treats the leading text as the return type, breaking documentation.
To Reproduce
Current behavior
https://i.imgur.com/9j01Hu2.png
Expected behavior
https://i.imgur.com/ea0PYae.png
(Note: I've modified the HTML file manually to include the colon here, just to show how I imagined it should look like)
Test project
Test.zip
Environment info
The text was updated successfully, but these errors were encountered: