question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

put source code below docstring

See original GitHub issue

Problem Description

When browsing documentation, the source code details are hidden and docstring appears in its natural place, right below the function definition … until you click the “view source” option. After clicking that option, source code appears between function definition and docstring … so docstring gets displaced down many lines (as many as the code length). So all the rich docstring format and all links it might contain disappear from our scope (until we close the source code).

  1. Default view:
<div class="attr function">...</div>     <details> <summary>View Source</summary>
<div class="codehilite"></div></details>   <---- HIDDEN STUFF
<div class="docstring">...</div>   <----   possible links to other modules and functions
  1. Click “view source”
<div class="attr function">...</div>     <details> <summary>View Source</summary>
    <div class="codehilite">
    ...
    ...
    ...
    ...
    ...
    ...
    ...
    ...
    ...
    ...
    </div>
</details>
<div class="docstring">...</div>   <----   Hey!!!  I was at top but I am here now. Move up & down to read me if you want.

Proposal

In my opinion, it might be much better to keep docstring below function definition, and put source code below docstring. So we can still see the nice docstring in its original place, and use the links to other functions and modules without having to move down.

<div class="attr function">...</div>
<div class="docstring">...</div>   <----   Don't worry. I am still here and will always be.
<details>
    <summary>View Source</summary>
    <div class="codehilite">
    ...
    ...
    ...
    ...
    ...
    ...
    ...
    ...
    ...
    ...
    </div>
</details>

Alternatives

Can I configure this using templates? Anyway, I think the default look would improve with this change.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
mhilscommented, Feb 4, 2022
0reactions
mhilscommented, Feb 5, 2022

huge characters because you forgot to escape <h1> in this function???

pdoc does not escape HTML tags in docstrings, this is expected behavior. pdoc.markdown2 is a vendored copy of the markdown2 library, which for practical reasons is included without any modifications (even if it’s somewhat ugly).

To appreciate its usefulness, you’ll have to pdocument a long and wide function (with many too-wide or very-indented lines of code), and see how it looks like with default pdoc css (unreadable right side of text).

I’m perfectly aware of the current layout. It will stay this way. pdoc displays a bit above 100 characters per line without scrolling. For reference, black has a maximum line length of 88 characters^1. It is very easy to scroll horizontally on all modern desktop OS and mobile devices. Yes, this is opinionated, but please accept that I’m not going to discuss it any further.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documenting Python Code: A Complete Guide
A complete guide to documenting Python code. Whether you're documenting a small script or a large project, whether you're a beginner or seasoned...
Read more >
Python Docstrings
It's specified in source code that is used, like a comment, to document a specific segment of code. Unlike conventional source code comments, ......
Read more >
Tutorial: Documenting in Python with Docstrings
Documenting your code is a critical skill for any data scientist or software engineer. This tutorial will show you how using docstrings.
Read more >
Python Docstrings (With Examples)
Python docstrings are the string literals that appear right after the definition of a function, method, class, or module. Let's take an example....
Read more >
Python Docstrings Tutorial : Examples & Format for Pydoc ...
See Python Docstrings. Learn about the different types of docstrings & various docstring formats like Sphinx, Numpy, and Pydoc with examples now.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found