Skip to content

Commit 38f79f2

Browse files
committed
fixes #778
1 parent 202ec96 commit 38f79f2

3 files changed

Lines changed: 41 additions & 9 deletions

File tree

fastcore/_modidx.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@
271271
'fastcore.docments.DocmentText._ret_str': ('docments.html#docmenttext._ret_str', 'fastcore/docments.py'),
272272
'fastcore.docments.DocmentText.params': ('docments.html#docmenttext.params', 'fastcore/docments.py'),
273273
'fastcore.docments.MarkdownRenderer': ('docments.html#markdownrenderer', 'fastcore/docments.py'),
274+
'fastcore.docments.MarkdownRenderer.__repr__': ( 'docments.html#markdownrenderer.__repr__',
275+
'fastcore/docments.py'),
274276
'fastcore.docments.MarkdownRenderer._repr_markdown_': ( 'docments.html#markdownrenderer._repr_markdown_',
275277
'fastcore/docments.py'),
276278
'fastcore.docments.ShowDocRenderer': ('docments.html#showdocrenderer', 'fastcore/docments.py'),

fastcore/docments.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,4 +429,9 @@ def _repr_markdown_(self):
429429
doc = f'```python\n\n{self.dm}\n\n```'
430430
if self.docs: doc += f"\n\n{_ital_first(self.docs)}"
431431
return doc
432-
__repr__=__str__=_repr_markdown_
432+
433+
def __repr__(self):
434+
doc = str(self.dm)
435+
if self.docs: doc += f'"""\n{self.docs}\n"""'
436+
return doc
437+
__str__=__repr__

nbs/04_docments.ipynb

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2485,7 +2485,12 @@
24852485
" doc = f'```python\\n\\n{self.dm}\\n\\n```'\n",
24862486
" if self.docs: doc += f\"\\n\\n{_ital_first(self.docs)}\"\n",
24872487
" return doc\n",
2488-
" __repr__=__str__=_repr_markdown_"
2488+
"\n",
2489+
" def __repr__(self):\n",
2490+
" doc = str(self.dm)\n",
2491+
" if self.docs: doc += f'\"\"\"\\n{self.docs}\\n\"\"\"'\n",
2492+
" return doc\n",
2493+
" __str__=__repr__"
24892494
]
24902495
},
24912496
{
@@ -2510,17 +2515,13 @@
25102515
"*Do a thing*"
25112516
],
25122517
"text/plain": [
2513-
"```python\n",
2514-
"\n",
25152518
"def _f(\n",
25162519
" a, b:callable=print, # param b\n",
25172520
" c:str='foo', # param c\n",
25182521
")->str: # Result of doing it\n",
2519-
"\n",
2520-
"\n",
2521-
"```\n",
2522-
"\n",
2523-
"*Do a thing*"
2522+
"\"\"\"\n",
2523+
"Do a thing\n",
2524+
"\"\"\""
25242525
]
25252526
},
25262527
"execution_count": null,
@@ -2539,6 +2540,30 @@
25392540
"MarkdownRenderer(_f)"
25402541
]
25412542
},
2543+
{
2544+
"cell_type": "code",
2545+
"execution_count": null,
2546+
"id": "0c739d71",
2547+
"metadata": {},
2548+
"outputs": [
2549+
{
2550+
"name": "stdout",
2551+
"output_type": "stream",
2552+
"text": [
2553+
"def _f(\n",
2554+
" a, b:callable=print, # param b\n",
2555+
" c:str='foo', # param c\n",
2556+
")->str: # Result of doing it\n",
2557+
"\"\"\"\n",
2558+
"Do a thing\n",
2559+
"\"\"\"\n"
2560+
]
2561+
}
2562+
],
2563+
"source": [
2564+
"print(MarkdownRenderer(_f))"
2565+
]
2566+
},
25422567
{
25432568
"cell_type": "code",
25442569
"execution_count": null,

0 commit comments

Comments
 (0)