|
1847 | 1847 | "| **Returns** | **int** | | |" |
1848 | 1848 | ], |
1849 | 1849 | "text/plain": [ |
1850 | | - "DocmentTbl(obj=<function _f at 0x135058540>, dm={'a': {'docment': 'description of param a', 'anno': <class 'inspect._empty'>, 'default': <class 'inspect._empty'>}, 'b': {'docment': 'description of param b', 'anno': <class 'bool'>, 'default': True}, 'c': {'docment': <class 'inspect._empty'>, 'anno': <class 'str'>, 'default': None}, 'return': {'docment': <class 'inspect._empty'>, 'anno': <class 'int'>, 'default': <class 'inspect._empty'>}}, verbose=True, returns=True, params=['a', 'b', 'c'])" |
| 1850 | + "DocmentTbl(obj=<function _f at 0x135fa8c20>, dm={'a': {'docment': 'description of param a', 'anno': <class 'inspect._empty'>, 'default': <class 'inspect._empty'>}, 'b': {'docment': 'description of param b', 'anno': <class 'bool'>, 'default': True}, 'c': {'docment': <class 'inspect._empty'>, 'anno': <class 'str'>, 'default': None}, 'return': {'docment': <class 'inspect._empty'>, 'anno': <class 'int'>, 'default': <class 'inspect._empty'>}}, verbose=True, returns=True, params=['a', 'b', 'c'])" |
1851 | 1851 | ] |
1852 | 1852 | }, |
1853 | 1853 | "execution_count": null, |
|
1925 | 1925 | "| **Returns** | **str** | | **Result of doing it** |" |
1926 | 1926 | ], |
1927 | 1927 | "text/plain": [ |
1928 | | - "DocmentTbl(obj=<function _f at 0x134ed3a60>, dm={'a': {'docment': <class 'inspect._empty'>, 'anno': <class 'inspect._empty'>, 'default': <class 'inspect._empty'>}, 'b': {'docment': 'param b', 'anno': <class 'int'>, 'default': <class 'inspect._empty'>}, 'c': {'docment': 'param c', 'anno': <class 'str'>, 'default': 'foo'}, 'return': {'docment': 'Result of doing it', 'anno': <class 'str'>, 'default': <class 'inspect._empty'>}}, verbose=True, returns=True, params=['a', 'b', 'c'])" |
| 1928 | + "DocmentTbl(obj=<function _f at 0x136032840>, dm={'a': {'docment': <class 'inspect._empty'>, 'anno': <class 'inspect._empty'>, 'default': <class 'inspect._empty'>}, 'b': {'docment': 'param b', 'anno': <class 'int'>, 'default': <class 'inspect._empty'>}, 'c': {'docment': 'param c', 'anno': <class 'str'>, 'default': 'foo'}, 'return': {'docment': 'Result of doing it', 'anno': <class 'str'>, 'default': <class 'inspect._empty'>}}, verbose=True, returns=True, params=['a', 'b', 'c'])" |
1929 | 1929 | ] |
1930 | 1930 | }, |
1931 | 1931 | "execution_count": null, |
|
2018 | 2018 | "| d | bool | True | description of param d |" |
2019 | 2019 | ], |
2020 | 2020 | "text/plain": [ |
2021 | | - "DocmentTbl(obj=<function _Test.foo at 0x13517e8e0>, dm={'c': {'docment': 'description of param c', 'anno': <class 'int'>, 'default': <class 'inspect._empty'>}, 'd': {'docment': 'description of param d', 'anno': <class 'bool'>, 'default': True}, 'return': {'docment': <class 'inspect._empty'>, 'anno': <class 'inspect._empty'>, 'default': <class 'inspect._empty'>}}, verbose=True, returns=True, params=['self', 'c', 'd'])" |
| 2021 | + "DocmentTbl(obj=<function _Test.foo at 0x135ffdbc0>, dm={'c': {'docment': 'description of param c', 'anno': <class 'int'>, 'default': <class 'inspect._empty'>}, 'd': {'docment': 'description of param d', 'anno': <class 'bool'>, 'default': True}, 'return': {'docment': <class 'inspect._empty'>, 'anno': <class 'inspect._empty'>, 'default': <class 'inspect._empty'>}}, verbose=True, returns=True, params=['self', 'c', 'd'])" |
2022 | 2022 | ] |
2023 | 2023 | }, |
2024 | 2024 | "execution_count": null, |
|
2097 | 2097 | "DocmentList(_f)" |
2098 | 2098 | ] |
2099 | 2099 | }, |
| 2100 | + { |
| 2101 | + "cell_type": "code", |
| 2102 | + "execution_count": null, |
| 2103 | + "id": "6355b569", |
| 2104 | + "metadata": {}, |
| 2105 | + "outputs": [], |
| 2106 | + "source": [ |
| 2107 | + "#| export\n", |
| 2108 | + "def _clean_text_sig(obj):\n", |
| 2109 | + " if not (sig := getattr(obj, '__text_signature__', None)): return None\n", |
| 2110 | + " sig = re.sub(r'\\$\\w+,?\\s*', '', sig)\n", |
| 2111 | + " return get_name(obj) + sig.replace('<unrepresentable>', '...')" |
| 2112 | + ] |
| 2113 | + }, |
2100 | 2114 | { |
2101 | 2115 | "cell_type": "code", |
2102 | 2116 | "execution_count": null, |
|
2125 | 2139 | " def params(self): return [(self._fmt_param(k,v), v.get('docment','')) for k,v in self.dm.items() if k != 'return']\n", |
2126 | 2140 | "\n", |
2127 | 2141 | " def __str__(self):\n", |
2128 | | - " lines,curr = [],[]\n", |
2129 | | - " for fmt,doc in self.params:\n", |
2130 | | - " comment = f' # {doc}' if doc else ''\n", |
2131 | | - " if curr and len(', '.join(curr))+len(fmt)+len(comment)>self.maxline:\n", |
2132 | | - " lines.append(', '.join(curr) + ',')\n", |
2133 | | - " curr = []\n", |
2134 | | - " curr.append(fmt)\n", |
2135 | | - " if doc: lines.append(', '.join(curr) + ',' + comment); curr = []\n", |
2136 | | - " if curr: lines.append(', '.join(curr))\n", |
2137 | | - " body = '\\n '.join(lines)\n", |
| 2142 | + " if (sig := _clean_text_sig(self.obj)) and not self.params: sig_str = f\"def {sig}\"\n", |
| 2143 | + " else:\n", |
| 2144 | + " lines,curr = [],[]\n", |
| 2145 | + " for fmt,doc in self.params:\n", |
| 2146 | + " comment = f' # {doc}' if doc else ''\n", |
| 2147 | + " if curr and len(', '.join(curr))+len(fmt)+len(comment)>self.maxline:\n", |
| 2148 | + " lines.append(', '.join(curr) + ',')\n", |
| 2149 | + " curr = []\n", |
| 2150 | + " curr.append(fmt)\n", |
| 2151 | + " if doc: lines.append(', '.join(curr) + ',' + comment); curr = []\n", |
| 2152 | + " if curr: lines.append(', '.join(curr))\n", |
| 2153 | + " sig_str = f\"def {get_name(self.obj)}(\\n {'\\n '.join(lines)}\\n{self._ret_str}\"\n", |
2138 | 2154 | " docstr = f' \"{self.obj.__doc__}\"' if self.docstring and self.obj.__doc__ else ''\n", |
2139 | | - " return f\"def {get_name(self.obj)}(\\n {body}\\n{self._ret_str}\\n{docstr}\"\n", |
| 2155 | + " return f\"{sig_str}\\n{docstr}\"\n", |
2140 | 2156 | " \n", |
2141 | 2157 | " __repr__ = __str__\n", |
2142 | 2158 | " def _repr_markdown_(self): return f\"```python\\n{self}\\n```\"" |
|
2541 | 2557 | "MarkdownRenderer(g)" |
2542 | 2558 | ] |
2543 | 2559 | }, |
| 2560 | + { |
| 2561 | + "cell_type": "code", |
| 2562 | + "execution_count": null, |
| 2563 | + "id": "7114d616", |
| 2564 | + "metadata": {}, |
| 2565 | + "outputs": [ |
| 2566 | + { |
| 2567 | + "data": { |
| 2568 | + "text/markdown": [ |
| 2569 | + "```python\n", |
| 2570 | + "\n", |
| 2571 | + "def next(iterator, default=..., /)\n", |
| 2572 | + "\n", |
| 2573 | + "\n", |
| 2574 | + "```\n", |
| 2575 | + "\n", |
| 2576 | + "*Return the next item from the iterator.*\n", |
| 2577 | + "\n", |
| 2578 | + "If default is given and the iterator is exhausted,\n", |
| 2579 | + "it is returned instead of raising StopIteration." |
| 2580 | + ], |
| 2581 | + "text/plain": [ |
| 2582 | + "```python\n", |
| 2583 | + "\n", |
| 2584 | + "def next(iterator, default=..., /)\n", |
| 2585 | + "\n", |
| 2586 | + "\n", |
| 2587 | + "```\n", |
| 2588 | + "\n", |
| 2589 | + "*Return the next item from the iterator.*\n", |
| 2590 | + "\n", |
| 2591 | + "If default is given and the iterator is exhausted,\n", |
| 2592 | + "it is returned instead of raising StopIteration." |
| 2593 | + ] |
| 2594 | + }, |
| 2595 | + "execution_count": null, |
| 2596 | + "metadata": {}, |
| 2597 | + "output_type": "execute_result" |
| 2598 | + } |
| 2599 | + ], |
| 2600 | + "source": [ |
| 2601 | + "MarkdownRenderer(next)" |
| 2602 | + ] |
| 2603 | + }, |
2544 | 2604 | { |
2545 | 2605 | "cell_type": "markdown", |
2546 | 2606 | "id": "51a04f95", |
|
0 commit comments