Documentation
https://www.sphinx-doc.org/en/master/usage/restructuredtext/domains.html#info-field-lists as of Sphinx==6.1.3
says they all render exactly the same for now, which is a shame:
In current release, all var, ivar and cvar are represented as “Variable”. There is no difference at all.
:ivar:
vs :cvar
minimal runnable example
Here's a minimal runnable example showing how they are likely meant to be used, and how the output looks like. As there is no rendering difference as of Sphinx==6.1.3
it is just a semantic thing for the source reader for the time being, but worth doing anyways.
Not showing :var:
because I'm not sure when that is meant to be used! Maybe module level variables would be the best? How to document a module constant in Python? But it doesn't work there from the module docstring.
main.py
class MyOtherClass:
"""
This class does that.
"""
pass
class MyClass:
"""
Description for class.
:ivar var1: Doc for var1
:ivar var2: Doc for var2.
Another line!
:cvar class_var: Syntax also works for class variables.
"""
class_var: int
def __init__(self, par1: int, par2: MyOtherClass):
self.var1: int = par1
self.var2: MyOtherClass = par2
def method(self):
"""
My favorite method.
"""
pass
@classmethod
def cmethod():
"""
My favorite class method.
"""
pass
build.sh
sphinx-build . out
conf.py
import os
import sys
sys.path.insert(0, os.path.abspath('.'))
extensions = [ 'sphinx.ext.autodoc' ]
autodoc_default_options = {
'members': True,
}
autodoc_typehints = "description"
index.rst
.. automodule:: main
requirements.txt
Sphinx==6.1.3
After ./build.sh
the output under out/index.html
looks like:

#:
doc comments
This is another way to document instance and class variables.
There are currently tradeoffs between both methods, it is a shame that there isn't one clearly superior method.
Downsides:
- the "Variables:" grouping looks cleaner, TODO link to feature request
Upsides:
- you don't have to type the attribute names multiple times
- types are shown
Both could be better:
- clearly show that
class_var
is a class variable? TODO link to feature request
Besides the self.var1 = par1 # Doc for var1
syntax you can also:
main.py
class MyClass:
"""
Description for class.
"""
#: Syntax also works for class variables.
class_var: int = 1
def __init__(self, par1: int, par2: MyOtherClass):
#: Doc for var1
self.var1: int = par1
#: Doc for var2.
#: Another line!
self.var2: MyOtherClass = par2
def method(self):
"""
My favorite method.
"""
pass
@classmethod
def cmethod():
"""
My favorite class method.
"""
pass
produces:

The #:
syntax is documented at: https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#directive-autoproperty
Tested on Python 3.10, Ubuntu 22.10.