chiark / gitweb /
documentation/python: handle also getset descriptors.
authorVladimír Vondruš <mosra@centrum.cz>
Sun, 14 Jul 2019 16:48:06 +0000 (18:48 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Sun, 14 Jul 2019 17:19:44 +0000 (19:19 +0200)
Ugh enough with those weird things already.

documentation/python.py
documentation/test_python/inspect_string/classes.html
documentation/test_python/inspect_string/inspect_string.DerivedException.html [new file with mode: 0644]
documentation/test_python/inspect_string/inspect_string.html
documentation/test_python/inspect_string/inspect_string/__init__.py
documentation/test_python/test_inspect.py

index 602d70890cdc04b1e99761af9340157cb08d7fc2..27ad2d1e2775d2244bcd19571e24c6b85cc39a53 100755 (executable)
@@ -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__):
index 617190ca58147f91d0134b49b607d3eec1a00bb9..e6a5895ab181c8e36c07fa8055f6d3a5353b4596 100644 (file)
@@ -43,6 +43,7 @@
                   <li>class <a href="inspect_string.subpackage.Foo.html" class="m-doc">Foo</a> <span class="m-doc">A class in a subpackage. Shouldn&#x27;t cause the module tree to have an expander for it.</span></li>
                 </ul>
               </li>
+              <li>class <a href="inspect_string.DerivedException.html" class="m-doc">DerivedException</a> <span class="m-doc">A class deriving from BaseException, which has the weird args getset_descriptor</span></li>
               <li class="m-doc-collapsible collapsed">
                 <a href="#" onclick="return toggle(this)">class</a> <a href="inspect_string.Foo.html" class="m-doc">Foo</a> <span class="m-doc">The foo class</span>
                 <ul class="m-doc">
diff --git a/documentation/test_python/inspect_string/inspect_string.DerivedException.html b/documentation/test_python/inspect_string/inspect_string.DerivedException.html
new file mode 100644 (file)
index 0000000..6fff166
--- /dev/null
@@ -0,0 +1,88 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+  <meta charset="UTF-8" />
+  <title>inspect_string.DerivedException | My Python Project</title>
+  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,400i,600,600i%7CSource+Code+Pro:400,400i,600" />
+  <link rel="stylesheet" href="m-dark+documentation.compiled.css" />
+  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+</head>
+<body>
+<header><nav id="navigation">
+  <div class="m-container">
+    <div class="m-row">
+      <a href="index.html" id="m-navbar-brand" class="m-col-t-8 m-col-m-none m-left-m">My Python Project</a>
+      <div class="m-col-t-4 m-hide-m m-text-right m-nopadr">
+        <a id="m-navbar-show" href="#navigation" title="Show navigation"></a>
+        <a id="m-navbar-hide" href="#" title="Hide navigation"></a>
+      </div>
+      <div id="m-navbar-collapse" class="m-col-t-12 m-show-m m-col-m-none m-right-m">
+        <div class="m-row">
+          <ol class="m-col-t-12 m-col-m-none">
+            <li><a href="modules.html">Modules</a></li>
+            <li><a href="classes.html">Classes</a></li>
+          </ol>
+        </div>
+      </div>
+    </div>
+  </div>
+</nav></header>
+<main><article>
+  <div class="m-container m-container-inflatable">
+    <div class="m-row">
+      <div class="m-col-l-10 m-push-l-1">
+        <h1>
+          <span class="m-breadcrumb"><a href="inspect_string.html">inspect_string</a>.<wbr/></span>DerivedException <span class="m-thin">class</span>
+        </h1>
+        <p>A class deriving from BaseException, which has the weird args getset_descriptor</p>
+        <div class="m-block m-default">
+          <h3>Contents</h3>
+          <ul>
+            <li>
+              Reference
+              <ul>
+                <li><a href="#methods">Methods</a></li>
+                <li><a href="#dunder-methods">Special methods</a></li>
+                <li><a href="#properties">Properties</a></li>
+              </ul>
+            </li>
+          </ul>
+        </div>
+        <section id="methods">
+          <h2><a href="#methods">Methods</a></h2>
+          <dl class="m-doc">
+            <dt>
+              <span class="m-doc-wrap-bumper">def <a href="#with_traceback" class="m-doc-self" id="with_traceback">with_traceback</a>(</span><span class="m-doc-wrap">...)</span>
+            </dt>
+            <dd>Exception.with_traceback(tb) --
+set self.__traceback__ to tb and return self.</dd>
+          </dl>
+        </section>
+        <section id="dunder-methods">
+          <h2><a href="#dunder-methods">Special methods</a></h2>
+          <dl class="m-doc">
+            <dt>
+              <span class="m-doc-wrap-bumper">def <a href="#__reduce__" class="m-doc-self" id="__reduce__">__reduce__</a>(</span><span class="m-doc-wrap">...)</span>
+            </dt>
+            <dd></dd>
+            <dt>
+              <span class="m-doc-wrap-bumper">def <a href="#__setstate__" class="m-doc-self" id="__setstate__">__setstate__</a>(</span><span class="m-doc-wrap">...)</span>
+            </dt>
+            <dd></dd>
+          </dl>
+        </section>
+        <section id="properties">
+          <h2><a href="#properties">Properties</a></h2>
+          <dl class="m-doc">
+            <dt>
+              <a href="#args" class="m-doc-self" id="args">args</a> <span class="m-label m-flat m-warning">get</span>
+            </dt>
+            <dd></dd>
+          </dl>
+        </section>
+      </div>
+    </div>
+  </div>
+</article></main>
+</body>
+</html>
index 5b7cf9701a4629c6237a2a58b48d660c90346c47..1722ce7d136d8317c4bbe84d0212ed5deebc0788 100644 (file)
@@ -62,6 +62,8 @@
         <section id="classes">
           <h2><a href="#classes">Classes</a></h2>
           <dl class="m-doc">
+            <dt>class <a href="inspect_string.DerivedException.html" class="m-doc">DerivedException</a></dt>
+            <dd>A class deriving from BaseException, which has the weird args getset_descriptor</dd>
             <dt>class <a href="inspect_string.Foo.html" class="m-doc">Foo</a></dt>
             <dd>The foo class</dd>
             <dt>class <a href="inspect_string.FooSlots.html" class="m-doc">FooSlots</a></dt>
index e9034255a760034c756567bc73b7f0eb88e86122..999087f19576559432a57d6cd337d1b66b4790a7 100644 (file)
@@ -112,6 +112,12 @@ class FooSlots:
 
     __slots__ = ['first', 'second']
 
+class DerivedException(BaseException):
+    """A class deriving from BaseException, which has the weird args getset_descriptor"""
+
+    # Note: once we properly handle properties of base classes, we might want
+    # to import BaseException and add it to __all__ so it gets parsed directly
+
 class Specials:
     """Special class members"""
 
index 25c0d75fa90cea212e84f09e2028022f8726dc1c..a4c2fa2f5a8e914e98f272569315d82929000ec8 100644 (file)
@@ -44,6 +44,7 @@ class String(BaseInspectTestCase):
         self.assertEqual(*self.actual_expected_contents('inspect_string.another_module.html'))
         self.assertEqual(*self.actual_expected_contents('inspect_string.Foo.html'))
         self.assertEqual(*self.actual_expected_contents('inspect_string.FooSlots.html'))
+        self.assertEqual(*self.actual_expected_contents('inspect_string.DerivedException.html'))
         self.assertEqual(*self.actual_expected_contents('inspect_string.Specials.html'))
 
         self.assertEqual(*self.actual_expected_contents('classes.html'))
@@ -67,6 +68,7 @@ class Object(BaseInspectTestCase):
         self.assertEqual(*self.actual_expected_contents('inspect_string.another_module.html', '../inspect_string/inspect_string.another_module.html'))
         self.assertEqual(*self.actual_expected_contents('inspect_string.Foo.html', '../inspect_string/inspect_string.Foo.html'))
         self.assertEqual(*self.actual_expected_contents('inspect_string.FooSlots.html', '../inspect_string/inspect_string.FooSlots.html'))
+        self.assertEqual(*self.actual_expected_contents('inspect_string.DerivedException.html', '../inspect_string/inspect_string.DerivedException.html'))
         self.assertEqual(*self.actual_expected_contents('inspect_string.Specials.html', '../inspect_string/inspect_string.Specials.html'))
 
         self.assertEqual(*self.actual_expected_contents('classes.html', '../inspect_string/classes.html'))