Title: Docstrings of "protected" members that are part of interfaces should be rendered · Issue #1848 · gitpython-developers/GitPython · GitHub
Open Graph Title: Docstrings of "protected" members that are part of interfaces should be rendered · Issue #1848 · gitpython-developers/GitPython
X Title: Docstrings of "protected" members that are part of interfaces should be rendered · Issue #1848 · gitpython-developers/GitPython
Description: GitPython classes contain a number of conceptually "protected" methods that can reasonably be called by code in subclasses (including in subclasses' overridden implementations of them) but not by arbitrary other code. By default, Sphinx ...
Open Graph Description: GitPython classes contain a number of conceptually "protected" methods that can reasonably be called by code in subclasses (including in subclasses' overridden implementations of them) but not by a...
X Description: GitPython classes contain a number of conceptually "protected" methods that can reasonably be called by code in subclasses (including in subclasses' overridden implementations of them...
Opengraph URL: https://github.com/gitpython-developers/GitPython/issues/1848
X: @github
Domain: Github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Docstrings of \"protected\" members that are part of interfaces should be rendered","articleBody":"GitPython classes contain a number of conceptually \"protected\" methods that can reasonably be called by code in subclasses (including in subclasses' overridden implementations of them) but not by arbitrary other code.\r\n\r\nBy default, Sphinx [autodoc](https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html) does not render documentation for entities that start with `_`. That makes sense for conceptually \"private\" things that don't make sense for outside code to call and that could, without warning, change or be removed at any time. But for \"protected\" methods, in order to correctly use them, it is useful to have documentation.\r\n\r\nAs one example, the public [`git.objects.tree.Tree.traverse`](https://gitpython.readthedocs.io/en/latest/reference.html#git.objects.tree.Tree.traverse) method has this as its docstring:\r\n\r\nhttps://github.com/gitpython-developers/GitPython/blob/fe1934c5c90e617d49a38a6c36b1eb17dea47013/git/objects/tree.py#L295-L298\r\n\r\nAlthough that can (and should) be made into a `:meth:` reference to [`Traversable._traverse`](https://github.com/gitpython-developers/GitPython/blob/fe1934c5c90e617d49a38a6c36b1eb17dea47013/git/objects/util.py#L444), doing so will not cause it to link to an rendered docstring for `Traversable._traverse`, because the `_traverse` method is non-public and there is currently nothing to link to for it in the rendered Sphinx documentation.\r\n\r\nThis could be mitigated in some specific cases by copying or moving documentation to fully public methods. For example, the `Tree.traverse` method could have all the relevant information present in the `Traversable._traverse` method. This would risk that information becoming out of date or otherwise confusing if it ends up being updated in one place but not another. But the real issue is that conceptually \"protected\" methods that document how they are and are not supposed to be used should--whether or not they are referenced in any other docstrings--be part of the rendered Sphinx documentation.\r\n\r\nSphinx autodoc generation is controlled by the code in `reference.rst` for each section of the reference manual. Currently most sections take the form:\r\n\r\nhttps://github.com/gitpython-developers/GitPython/blob/fe1934c5c90e617d49a38a6c36b1eb17dea47013/doc/source/reference.rst?plain=1#L48-L51\r\n\r\nSphinx autodoc supports [`:private-members:`](https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#directive-option-automodule-private-members), which can be used to emit documentation for just some specifically named non-public members (rather than all) by giving them as arguments. But I suspect that this may not be the best way to do it. Each entity in GitPython that has specific documentation currently has it in the form of a docstring on that entity. So if possible, this should be controlled from the docstrings themselves. (Of course, if this is not feasible, then it is better to list them explicitly in `reference.rst` than to keep their documentation omitted forever.)\r\n\r\nFixing this may help with #1834, especially if the non-`None` usage to be documented is not going to be deprecated, since the recommendation to prefer returning `None` will probably have to be written in the docstring, and for this to really be clear the docstring should be rendered. However, I don't think this needs to be seen as a blocker for that, and I don't want to discourage anyone from fixing #1834 at any time.\r\n\r\nFinally, note that sometimes the word \"protected\" is used in Python jargon to mean methods named like `_foo` rather than `__foo`. That's not what I mean; I am using this word in the traditional OOP sense to refer to members that are considered part of the interface for subclasses but not part of the interface more broadly. Most `_foo` methods in GitPython are conceptually private and should not have their docstrings emitted by Sphinx.","author":{"url":"https://github.com/EliahKagan","@type":"Person","name":"EliahKagan"},"datePublished":"2024-02-27T17:27:07.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/1848/GitPython/issues/1848"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f6ec2c41-edff-b5be-c8dd-66510f2f6719 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B6E8:6E24C:7EF026:B01349:6A624576 |
| html-safe-nonce | 8f69fa30b0caec794e93c3cd0fdcb3d5402d9421d9e5fc42d0beeb8d1963c610 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNkU4OjZFMjRDOjdFRjAyNjpCMDEzNDk6NkE2MjQ1NzYiLCJ2aXNpdG9yX2lkIjoiOTA5MzkzOTg2MTk4NTA1MjAyMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 0dda2d1b0c5ce7fd06e4ad96e15f2517b6dbf32eb2c442ec5cf13165a8facae1 |
| hovercard-subject-tag | issue:2157236111 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/gitpython-developers/GitPython/1848/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2b376f9200456469b69a65f31364d8f9a259bead1f42fe23fb9f7ba09dbc6f63/gitpython-developers/GitPython/issues/1848 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2b376f9200456469b69a65f31364d8f9a259bead1f42fe23fb9f7ba09dbc6f63/gitpython-developers/GitPython/issues/1848 |
| og:image:alt | GitPython classes contain a number of conceptually "protected" methods that can reasonably be called by code in subclasses (including in subclasses' overridden implementations of them) but not by a... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | EliahKagan |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5d6ba65d73ecc4e3394fe318d2b2f98e6f8eed4878b5421b938e20d30bde267b |
| turbo-cache-control | no-preview |
| go-import | github.com/gitpython-developers/GitPython git https://github.com/gitpython-developers/GitPython.git |
| octolytics-dimension-user_id | 503709 |
| octolytics-dimension-user_login | gitpython-developers |
| octolytics-dimension-repository_id | 1126087 |
| octolytics-dimension-repository_nwo | gitpython-developers/GitPython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1126087 |
| octolytics-dimension-repository_network_root_nwo | gitpython-developers/GitPython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2dadc56fd5989b76a8ae7304e3aa56d0b485e5dc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width