Skip to content
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

Consider allowing ivar and cvar (and vartype) for attributes in sphinx style #150

Open
tmke8 opened this issue Jul 9, 2024 · 1 comment

Comments

@tmke8
Copy link

tmke8 commented Jul 9, 2024

These are little-known fields, but they are documented here: https://www.sphinx-doc.org/en/master/usage/domains/python.html#info-field-lists

ivar is for instance attributes and cvar is for class attributes, so:

from typing import ClassVar

class A:
  """My class

  :ivar n: Number of items.
  :cvar threshold: Threshold for items.
  """

  n: int
  threshold: ClassVar[int] = 3
  
  def __init__(self) -> None:
    self.n = 2

If you wanted to specify a type you could do it with vartype.

The main advantage over the .. attribute:: syntax is that it's more compact, which is why I prefer it.

@jsh9
Copy link
Owner

jsh9 commented Jul 17, 2024

Thanks for sharing this! I didn't know about this until seeing your post.

I'd like to support this, but it requires non trivial code changes:

The first part is more time consuming. I can get to it in the next few weeks (or longer, depending on my availability). But if you'd like to take a stab at it, I'd really appreciate it! (I opened an issue there: jsh9/docstring_parser_fork#9)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants