Title: Share code for getdoc() between inspect and pydoc · Issue #132686 · python/cpython · GitHub
Open Graph Title: Share code for getdoc() between inspect and pydoc · Issue #132686 · python/cpython
X Title: Share code for getdoc() between inspect and pydoc · Issue #132686 · python/cpython
Description: Currently, inspect and pydoc use similar, but slightly different complex code to retrieve a doc string for object (class, function, method, etc). This is a consequence of two issues: bpo-15582 (#59787) and bpo-40257 (#84438). In #59787, ...
Open Graph Description: Currently, inspect and pydoc use similar, but slightly different complex code to retrieve a doc string for object (class, function, method, etc). This is a consequence of two issues: bpo-15582 (#59...
X Description: Currently, inspect and pydoc use similar, but slightly different complex code to retrieve a doc string for object (class, function, method, etc). This is a consequence of two issues: bpo-15582 (#59...
Opengraph URL: https://github.com/python/cpython/issues/132686
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Share code for getdoc() between inspect and pydoc","articleBody":"Currently, `inspect` and `pydoc` use similar, but slightly different complex code to retrieve a doc string for object (class, function, method, etc). This is a consequence of two issues: bpo-15582 (#59787) and bpo-40257 (#84438).\n\nIn #59787, inheriting docstrings from parent class was added. It usually works fine for overridden methods, but for classes it is often wrong. If the parent class docstring says that it is an abstract class, a base class or a generic implementation class, showing this for a subclass is wrong. It is worse than not showing a docstring at all (like it was before #59787). So #84438 reverted this particular change. It fixed also other issue -- `pydoc` now shows a docstring not only for classes and function, but for arbitrary objects if they have docstring. This allows to show docstring for `typing.Any` and other pseudo-types. But there were complains against these changes, so they were reverted for `inspect.getdoc()`. But taht behavior is wrong for `pydoc`, so a modified version of `inspect.getdoc()` was copied in `pydoc`.\n\nThe problem is that that code is pretty complex. And any time we change it (for example #131116), we need to change in two places. It is easy to forgot to synchronize the code or introduce a bug. Also, the third-party code that use `getdoc()` may need the behavior of the `pydoc` version, which is not public.\n\nThe implementation should be shared. We may add options to control the behavior, and the default behavior may change in future. If there is a way to get the old behavior, there would be less complains.\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-132691\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/serhiy-storchaka","@type":"Person","name":"serhiy-storchaka"},"datePublished":"2025-04-18T13:07:21Z","url":"https://github.com/python/cpython/issues/132686"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| 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:966511f0-87e5-8892-267d-a8d9ff781e5f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C218:F089C:20851D:2B9370:6AECC430 |
| html-safe-nonce | e9f15aa052b6b111d7daa48add5bdc56bce1dcda4d8c406fe2def928778029db |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMjE4OkYwODlDOjIwODUxRDoyQjkzNzA6NkFFQ0M0MzAiLCJ2aXNpdG9yX2lkIjoiNDk5ODUyMTUxMzk3OTk4Njk5MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 880a9ee8d7f28a527095f0a4f89ddea7721cdaf0609a3b61869297f2fb6c4493 |
| hovercard-subject-tag | issue:3004924699 |
| 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/python/cpython/132686/issue_layout |
| twitter:image | https://opengraph.githubassets.com/22e3b5a8d86badd4fb0061a9b7279d27aed00bd98fec164d9a276d24bbbafea4/python/cpython/issues/132686 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/22e3b5a8d86badd4fb0061a9b7279d27aed00bd98fec164d9a276d24bbbafea4/python/cpython/issues/132686 |
| og:image:alt | Currently, inspect and pydoc use similar, but slightly different complex code to retrieve a doc string for object (class, function, method, etc). This is a consequence of two issues: bpo-15582 (#59... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | serhiy-storchaka |
| hostname | github.com |
| expected-hostname | github.com |
| None | dc0b519c5798dc1150b88dc4c06a8b9634d0069218dc04e469970e76aad74016 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| 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 | db139f0bf57b59bf9a8c4abb0849924d6c6ca559 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width