Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inspect.getdoc does find inherited property __doc__ #69689

Closed
jayvdb mannequin opened this issue Oct 29, 2015 · 3 comments
Closed

inspect.getdoc does find inherited property __doc__ #69689

jayvdb mannequin opened this issue Oct 29, 2015 · 3 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@jayvdb
Copy link
Mannequin

jayvdb mannequin commented Oct 29, 2015

BPO 25503
Nosy @serhiy-storchaka, @jayvdb
Files
  • getdoc-property.diff: Fix and test case
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2015-10-29.06:22:55.074>
    created_at = <Date 2015-10-29.04:53:40.598>
    labels = ['type-bug', 'library']
    title = 'inspect.getdoc does find inherited property __doc__'
    updated_at = <Date 2015-10-29.06:22:55.073>
    user = 'https://github.com/jayvdb'

    bugs.python.org fields:

    activity = <Date 2015-10-29.06:22:55.073>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2015-10-29.06:22:55.074>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2015-10-29.04:53:40.598>
    creator = 'jayvdb'
    dependencies = []
    files = ['40885']
    hgrepos = []
    issue_num = 25503
    keywords = ['patch']
    message_count = 3.0
    messages = ['253653', '253659', '253660']
    nosy_count = 3.0
    nosy_names = ['python-dev', 'serhiy.storchaka', 'jayvdb']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue25503'
    versions = ['Python 3.5', 'Python 3.6']

    @jayvdb
    Copy link
    Mannequin Author

    jayvdb mannequin commented Oct 29, 2015

    inspect.getdoc's helper _finddoc raises an AttributeError on encountering a property, which is silently discarded.

    >>> class Foo(object):
    ...     @property
    ...     def foo(self):
    ...         """foobar."""
    ...         return 'foo'
    ... 
    >>> class Bar(Foo):
    ...     @property
    ...     def foo(self):
    ...         return 'bar'
    ... 
    >>> import inspect
    >>> inspect.getdoc(Foo.foo)
    'foobar.'
    >>> inspect.getdoc(Bar.foo)
    >>>

    How I came upon this was doing static code analysis, and the f.fget on line 522 here looks very wrong.

    http://bugs.python.org/review/15582/diff/14140/Lib/inspect.py

    This code dedicated to supporting property does not work because of that, but also because a property is also a data descriptor so the 'property' branch is never executed.

    >>> inspect.isdatadescriptor(property())
    True

    @jayvdb jayvdb mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Oct 29, 2015
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 29, 2015

    New changeset bbf00faf25ff by Serhiy Storchaka in branch '3.5':
    Issue bpo-25503: Fixed inspect.getdoc() for inherited docstrings of properties.
    https://hg.python.org/cpython/rev/bbf00faf25ff

    New changeset e80d1e9737d4 by Serhiy Storchaka in branch 'default':
    Issue bpo-25503: Fixed inspect.getdoc() for inherited docstrings of properties.
    https://hg.python.org/cpython/rev/e80d1e9737d4

    @serhiy-storchaka
    Copy link
    Member

    Thank you John for your report and your patch.

    Committed tests are slightly changed because "contradiction" was originally purposed to test properties.

    @serhiy-storchaka serhiy-storchaka self-assigned this Oct 29, 2015
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant