From 85a2577d92e5bc38b7e24cbf4f25ad7296722b60 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 14 Jul 2019 18:48:06 +0200 Subject: [PATCH] documentation/python: handle also getset descriptors. Ugh enough with those weird things already. --- documentation/python.py | 15 ++++ .../test_python/inspect_string/classes.html | 1 + .../inspect_string.DerivedException.html | 88 +++++++++++++++++++ .../inspect_string/inspect_string.html | 2 + .../inspect_string/inspect_string/__init__.py | 6 ++ documentation/test_python/test_inspect.py | 2 + 6 files changed, 114 insertions(+) create mode 100644 documentation/test_python/inspect_string/inspect_string.DerivedException.html 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