GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Share code for getdoc() between inspect and pydoc · Issue #132686 · python/cpython

Share code for getdoc() between inspect and pydoc #132686

New issue
Copy link
New issue
Copy link
Closed
Closed
Share code for getdoc() between inspect and pydoc#132686
Copy link
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

Description

@serhiy-storchaka
serhiy-storchaka
opened on Apr 18, 2025
Issue body actions

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, 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.

The 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.

The 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.

Linked PRs

  • gh-132686: Add parameters inherit_class_doc and fallback_to_class_doc for inspect.getdoc() #132691

Activity

  1. serhiy-storchaka
    added this to Inspect issues 🔍on Apr 18, 2025
  2. picnixz
    added
    type-featureA feature request or enhancementA feature request or enhancement
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    on Apr 18, 2025
  3. thomashammett commented on Apr 18, 2025

    @thomashammett
    thomashammett
    on Apr 18, 2025
    More actions

    I'd like to work on this issue and submit a PR to fix it. Is anyone already working on this, or may I take it? Thank you.

  4. serhiy-storchaka
    added a commit that references this issue on Apr 18, 2025

    pythongh-132686: Add parameters inherit_class_doc and fallback_to_cla…

    f5bdb78
  5. serhiy-storchaka commented on Apr 18, 2025

    @serhiy-storchaka
    serhiy-storchaka
    on Apr 18, 2025
    MemberAuthor
    More actions

    #132691 adds new options for getdoc().

    @ncoghlan, @vadmium, @vedgar, @Carreau, @gvanrossum, what are your thoughts about these options?

  6. serhiy-storchaka commented on Apr 18, 2025

    @serhiy-storchaka
    serhiy-storchaka
    on Apr 18, 2025
    MemberAuthor
    More actions

    Sorry, @thomashammett, the work was already almost done when I created this issue.

  7. thomashammett commented on Apr 18, 2025

    @thomashammett
    thomashammett
    on Apr 18, 2025
    More actions

    No worries! Thanks.

  8. vedgar commented on Apr 20, 2025

    @vedgar
    vedgar
    on Apr 20, 2025
    Contributor
    More actions

    #132691 adds new options for getdoc().

    @ncoghlan, @vadmium, @vedgar, @Carreau, @gvanrossum, what are your thoughts about these options?

    I'm not quite sure why I was mentioned here... is there a particular reason you want my opinion?

  9. serhiy-storchaka commented on Apr 20, 2025

    @serhiy-storchaka
    serhiy-storchaka
    on Apr 20, 2025
    MemberAuthor
    More actions

    Because you were one of the opponents of unconditional change in #84438.
    #84438 (comment)
    #84438 (comment)

  10. vedgar commented on Apr 20, 2025

    @vedgar
    vedgar
    on Apr 20, 2025 via email
    Contributor
    More actions
    But if I understood correctly, the default behavior of help now remains the same, right? That's the whole thing I wanted to preserve. ~V. ned, 20. tra 2025. 11:18 Serhiy Storchaka ***@***.***> je napisao:
    …
    Because you were one of the opponents of unconditional change in #84438 <#84438>. #84438 (comment) <#84438 (comment)> #84438 (comment) <#84438 (comment)> — Reply to this email directly, view it on GitHub <#132686 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ACGTVAUDXZJ6QCTOLVNCNYL22NQ7VAVCNFSM6AAAAAB3NAQMBKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDQMJXGA4DAMZSGM> . You are receiving this because you were mentioned.Message ID: ***@***.***> *serhiy-storchaka* left a comment (python/cpython#132686) <#132686 (comment)> Because you were one of the opponents of unconditional change in #84438 <#84438>. #84438 (comment) <#84438 (comment)> #84438 (comment) <#84438 (comment)> — Reply to this email directly, view it on GitHub <#132686 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ACGTVAUDXZJ6QCTOLVNCNYL22NQ7VAVCNFSM6AAAAAB3NAQMBKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDQMJXGA4DAMZSGM> . You are receiving this because you were mentioned.Message ID: ***@***.***>
  11. serhiy-storchaka
    added a commit that references this issue on Nov 11, 2025

    gh-132686: Add parameters inherit_class_doc and fallback_to_class_doc…

    7906f4d
  12. serhiy-storchaka
    closed this as completedon Nov 11, 2025
  13. github-project-automation
    moved this to Done in Inspect issues 🔍on Nov 11, 2025
  14. StanFromIreland
    added a commit that references this issue on Dec 6, 2025

    pythongh-132686: Add parameters inherit_class_doc and fallback_to_cla…

    40f16e5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

    Projects

    • Inspect issues 🔍
      Status
      Done
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.