Replies: 1 comment 1 reply
-
@sirosen I fear there are few (if any) good methods for properly detecting custom class property decorators. We would need some reliable indicator; I don't want to be in the business of introspecting decorator function/class bodies. How bad would it be to need to mark classmethod status on the autodoc directive? For example: .. autoproperty:: stephens_read_only_classproperty
:classmethod: The other 'obvious' option is to invent a custom dunder to set, but this equally has several drawbacks. A |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
In Python 3.9, we were allowed to stack
classmethod
withproperty
, before the problems with this pattern were fully realized. Sphinx added support for this to autodoc, but support for these descriptors being composed was pulled in Python 3.10.As Python 3.9 EOL approaches, it seems appropriate to think of the future of Sphinx support for class properties. There are several third-party implementations, making various tradeoffs, and it's easy to write your own read-only one, e.g.:
Because autodoc treats stacked decorators as indicating classproperty-ness, you can make a sphinx-friendly version by detecting whether or not a doc build is running and dispatching between implementations. e.g.,
This works great! But it doesn't seem certain that it will last.
classmethod(property(...))
only works in CPython 3.9, no other versions, and probably not at all in other implementations.Looking at the Python Domain definition,
py:property
has a:classmethod:
option. That seems less likely to be removed -- since various third-party implementations of class properties exist, this is a good way to document them.So! I'm very curious. What's the best way, long-term, for users of class properties to document them? Right now, I'm considering switching off of the build-detection approach (I'm doing it by checking
sys.argv[0]
, but other methods are possible) and onto an explicitpy:property
definition.Beta Was this translation helpful? Give feedback.
All reactions