From: Vladimír Vondruš Date: Sun, 14 Jul 2019 16:48:06 +0000 (+0200) Subject: documentation/python: handle also getset descriptors. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=85a2577d92e5bc38b7e24cbf4f25ad7296722b60;p=blog.git documentation/python: handle also getset descriptors. Ugh enough with those weird things already. --- diff --git a/documentation/python.py b/documentation/python.py index 602d7089..27ad2d1e 100755 --- a/documentation/python.py +++ b/documentation/python.py @@ -1121,6 +1121,21 @@ def extract_property_doc(state: State, parent, path: List[str], property): return out + # The properties can be defined using the low-level descriptor protocol + # instead of the higher-level property() decorator. That means there's no + # fget / fset / fdel, instead we need to look into __get__ / __set__ / + # __delete__ directly. This is fairly rare (datetime.date is one and + # BaseException.args is another I could find), so don't bother with it much + # --- assume readonly and no docstrings / annotations whatsoever. + if property.__class__.__name__ == 'getset_descriptor' and property.__class__.__module__ == 'builtins': + out.is_gettable = True + out.is_settable = False + out.is_deletable = False + out.summary = '' + out.has_details = False + out.type = None + return out + # TODO: external summary for properties out.is_gettable = property.fget is not None if property.fget or (property.fset and property.__doc__): diff --git a/documentation/test_python/inspect_string/classes.html b/documentation/test_python/inspect_string/classes.html index 617190ca..e6a5895a 100644 --- a/documentation/test_python/inspect_string/classes.html +++ b/documentation/test_python/inspect_string/classes.html @@ -43,6 +43,7 @@
  • class Foo A class in a subpackage. Shouldn't cause the module tree to have an expander for it.
  • +
  • class DerivedException A class deriving from BaseException, which has the weird args getset_descriptor