chiark / gitweb /
documentation/python: properly shrink first column also with skipped self.
authorVladimír Vondruš <mosra@centrum.cz>
Wed, 28 Aug 2019 22:32:01 +0000 (00:32 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Fri, 30 Aug 2019 14:47:58 +0000 (16:47 +0200)
This will break if the docs skip undocumented parameters, but since that's
technically an error, I don't care.

documentation/templates/python/details-function.html
documentation/test_python/content/content.Class.html
documentation/test_python/inspect_attrs/docs.rst [new file with mode: 0644]
documentation/test_python/inspect_attrs/inspect_attrs.py [new file with mode: 0644]

index f48e1818d5b9b58dfca56536c7da90e9051a1f83..1bce6420a5224d8fbc8abaf2b058581b1cdc6159 100644 (file)
@@ -16,7 +16,7 @@
                 {% for param in function.params %}
                 {% if loop.index != 1 or param.name != 'self' or param.content %}
                 <tr>
-                  <td{% if loop.index == 1 %} style="width: 1%"{% endif %}>{{ param.name }}</td>
+                  <td{% if loop.index == 1 or loop.index == 2 and function.params[loop.index0 - 1].name == 'self' %} style="width: 1%"{% endif %}>{{ param.name }}</td>
                   <td>{{ param.content }}</td>
                 </tr>
                 {% endif %}
index 5f4320f6caf518929944a9d903248a6c992106f4..81d2eff44bd2f4393a9878b26dd5dcc1974edf6d 100644 (file)
@@ -140,7 +140,7 @@ add any detailed block.</dd>
               </thead>
               <tbody>
                 <tr>
-                  <td>a</td>
+                  <td style="width: 1%">a</td>
                   <td>The first parameter</td>
                 </tr>
                 <tr>
diff --git a/documentation/test_python/inspect_attrs/docs.rst b/documentation/test_python/inspect_attrs/docs.rst
new file mode 100644 (file)
index 0000000..153f558
--- /dev/null
@@ -0,0 +1,18 @@
+.. py:property:: inspect_attrs.MyClass.unannotated
+    :summary: External docs for this property
+
+.. py:property:: inspect_attrs.MyClassAutoAttribs.complex_annotation
+    :summary: This is complex.
+
+.. py:data:: inspect_attrs.MySlotClass.annotated
+    :summary: This is a float slot.
+
+.. py:function:: inspect_attrs.MyClass.__init__
+    :summary: External docs for the init
+    :param annotated: The first argument
+    :param unannotated: This gets the default of four
+    :param complex_annotation: Yes, a list
+    :param hidden_property: Interesting, but I don't care.
+
+    The :p:`hidden_property` isn't shown in the output as it's prefixed with
+    an underscore.
diff --git a/documentation/test_python/inspect_attrs/inspect_attrs.py b/documentation/test_python/inspect_attrs/inspect_attrs.py
new file mode 100644 (file)
index 0000000..cf3ef99
--- /dev/null
@@ -0,0 +1,29 @@
+from typing import List, Tuple
+
+import attr
+
+@attr.s
+class MyClass:
+    """A class with attr-defined properties"""
+
+    annotated: float = attr.ib()
+    unannotated = attr.ib(4)
+    complex_annotation: List[Tuple[int, float]] = attr.ib(default=[])
+
+    # Shouldn't be shown
+    _hidden_property: float = attr.ib(3)
+
+@attr.s(auto_attribs=True)
+class MyClassAutoAttribs:
+    """A class with automatic attr-defined properties"""
+
+    annotated: float
+    unannotated = 4
+    complex_annotation: List[Tuple[int, float]] = []
+
+@attr.s(auto_attribs=True, slots=True)
+class MySlotClass:
+    """A class with attr-defined slots"""
+
+    annotated: float
+    complex_annotation: List[Tuple[int, float]] = []