|
399 | 399 | { |
400 | 400 | "cell_type": "code", |
401 | 401 | "execution_count": null, |
402 | | - "id": "f5efac13", |
| 402 | + "id": "da0465e3", |
403 | 403 | "metadata": {}, |
404 | 404 | "outputs": [], |
405 | 405 | "source": [ |
406 | 406 | "#| export\n", |
407 | 407 | "def get_name(obj):\n", |
408 | 408 | " \"Get the name of `obj`\"\n", |
| 409 | + " if isinstance(obj, partial):\n", |
| 410 | + " nm = get_name(obj.func)\n", |
| 411 | + " args = [repr(a) for a in obj.args] + [f'{k}={repr(v)}' for k,v in obj.keywords.items()]\n", |
| 412 | + " return f\"{nm}[partial: {', '.join(args)}]\"\n", |
409 | 413 | " if hasattr(obj, '__name__'): return obj.__name__\n", |
410 | 414 | " elif getattr(obj, '_name', False): return obj._name\n", |
411 | | - " elif hasattr(obj,'__origin__'): return str(obj.__origin__).split('.')[-1] #for types\n", |
| 415 | + " elif hasattr(obj,'__origin__'): return str(obj.__origin__).split('.')[-1]\n", |
412 | 416 | " elif type(obj)==property: return _get_property_name(obj)\n", |
413 | 417 | " else: return str(obj).split('.')[-1]" |
414 | 418 | ] |
|
1843 | 1847 | "| **Returns** | **int** | | |" |
1844 | 1848 | ], |
1845 | 1849 | "text/plain": [ |
1846 | | - "DocmentTbl(obj=<function _f at 0x131f0efc0>, 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 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'])" |
1847 | 1851 | ] |
1848 | 1852 | }, |
1849 | 1853 | "execution_count": null, |
|
1921 | 1925 | "| **Returns** | **str** | | **Result of doing it** |" |
1922 | 1926 | ], |
1923 | 1927 | "text/plain": [ |
1924 | | - "DocmentTbl(obj=<function _f at 0x131f0f060>, 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 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'])" |
1925 | 1929 | ] |
1926 | 1930 | }, |
1927 | 1931 | "execution_count": null, |
|
2014 | 2018 | "| d | bool | True | description of param d |" |
2015 | 2019 | ], |
2016 | 2020 | "text/plain": [ |
2017 | | - "DocmentTbl(obj=<function _Test.foo at 0x131e5c040>, 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 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'])" |
2018 | 2022 | ] |
2019 | 2023 | }, |
2020 | 2024 | "execution_count": null, |
|
2132 | 2136 | " if curr: lines.append(', '.join(curr))\n", |
2133 | 2137 | " body = '\\n '.join(lines)\n", |
2134 | 2138 | " docstr = f' \"{self.obj.__doc__}\"' if self.docstring and self.obj.__doc__ else ''\n", |
2135 | | - " return f\"def {self.obj.__name__}(\\n {body}\\n{self._ret_str}\\n{docstr}\"\n", |
| 2139 | + " return f\"def {get_name(self.obj)}(\\n {body}\\n{self._ret_str}\\n{docstr}\"\n", |
2136 | 2140 | " \n", |
2137 | 2141 | " __repr__ = __str__\n", |
2138 | 2142 | " def _repr_markdown_(self): return f\"```python\\n{self}\\n```\"" |
|
2234 | 2238 | "DocmentText(_g, maxline=80, docstring=False)" |
2235 | 2239 | ] |
2236 | 2240 | }, |
| 2241 | + { |
| 2242 | + "cell_type": "code", |
| 2243 | + "execution_count": null, |
| 2244 | + "id": "88807401", |
| 2245 | + "metadata": {}, |
| 2246 | + "outputs": [ |
| 2247 | + { |
| 2248 | + "data": { |
| 2249 | + "text/markdown": [ |
| 2250 | + "```python\n", |
| 2251 | + "def _g[partial: 1](\n", |
| 2252 | + " b:int, cccccccccccccccccccc:int, ccccccccdccccccccccc:int,\n", |
| 2253 | + " cccccccccccecccccccc:int, cccccccfcccccccccc:int, ccccccccccccgccccc:int,\n", |
| 2254 | + " c:str='foo'\n", |
| 2255 | + ")->str:\n", |
| 2256 | + "\n", |
| 2257 | + "```" |
| 2258 | + ], |
| 2259 | + "text/plain": [ |
| 2260 | + "def _g[partial: 1](\n", |
| 2261 | + " b:int, cccccccccccccccccccc:int, ccccccccdccccccccccc:int,\n", |
| 2262 | + " cccccccccccecccccccc:int, cccccccfcccccccccc:int, ccccccccccccgccccc:int,\n", |
| 2263 | + " c:str='foo'\n", |
| 2264 | + ")->str:" |
| 2265 | + ] |
| 2266 | + }, |
| 2267 | + "execution_count": null, |
| 2268 | + "metadata": {}, |
| 2269 | + "output_type": "execute_result" |
| 2270 | + } |
| 2271 | + ], |
| 2272 | + "source": [ |
| 2273 | + "DocmentText(partial(_g, 1), maxline=80, docstring=False)" |
| 2274 | + ] |
| 2275 | + }, |
2237 | 2276 | { |
2238 | 2277 | "cell_type": "code", |
2239 | 2278 | "execution_count": null, |
|
0 commit comments