Closed eladyn closed 3 years ago
Thanks for the clear bug report. The issue seems to be the -1 here: https://github.com/pdoc3/pdoc/blob/bec63077a03b2136e6982825d327073ed76cc20a/pdoc/html_helpers.py#L563-L564 Not sure why, though. Welcome an investigation/PR.
Thank you for the quick response.
I did some further investigation and it seems that the real problem is an undocumented behavior of the getsourcelines(object)
function in the inspect
module.
The docstring for this function says:
Return a list of source lines and starting line number for an object.
However, when looking through the source code of this function, I found: https://github.com/python/cpython/blob/39a7578186d2f5eaa112a5854c46f84eae401522/Lib/inspect.py#L1011-L1016
This causes the function to return 0 as start_line for modules and for other objects the real line number (which is done with lnum + 1
).
I also found a similar looking thing in the findsource function which is called by getsourcelines()
so it seems to be "intended" behavior.
Therefore, I think this could easily be fixed by adding a check like (I just tried it locally and it seems to be working)
if start_line == 0:
start_line = 1
I can of course start a PR if you think that the above makes sense.
Python bug, the usual. Excellent detective work. start_line = start_line or 1 # GH-296
seems a reasonable fix on our end. :+1:
Sorry for the late reply. Should I create a pull request for your fix or are you going to directly commit it to master?
Expected Behavior
The generated "BROWSE GIT" link for a module should be generated with
start_line = 1
andend_line
similarly with the correct last line number.Actual Behavior
It is generated with
start_line = 0
andend_line
correspondingly with the last linenumber reduced by 1.Steps to Reproduce
Additional info
Every class, function, method or variable docstrings "BROWSE GIT"-link I have tried yet worked, so it seems to be specific to the module docstrings.