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

Docstrings should refer to help(name), not name.__doc__ #53229

Closed
abalkin opened this issue Jun 12, 2010 · 7 comments
Closed

Docstrings should refer to help(name), not name.__doc__ #53229

abalkin opened this issue Jun 12, 2010 · 7 comments
Assignees
Labels
docs Documentation in the Doc dir type-feature A feature request or enhancement

Comments

@abalkin
Copy link
Member

abalkin commented Jun 12, 2010

BPO 8983
Nosy @birkenfeld, @mdickinson, @abalkin, @merwok
Files
  • issue8983.diff
  • 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/abalkin'
    closed_at = <Date 2010-08-16.20:22:31.503>
    created_at = <Date 2010-06-12.15:26:32.887>
    labels = ['type-feature', 'docs']
    title = 'Docstrings should refer to help(name), not name.__doc__'
    updated_at = <Date 2010-08-16.20:22:31.502>
    user = 'https://github.com/abalkin'

    bugs.python.org fields:

    activity = <Date 2010-08-16.20:22:31.502>
    actor = 'belopolsky'
    assignee = 'belopolsky'
    closed = True
    closed_date = <Date 2010-08-16.20:22:31.503>
    closer = 'belopolsky'
    components = ['Documentation']
    creation = <Date 2010-06-12.15:26:32.887>
    creator = 'belopolsky'
    dependencies = []
    files = ['17647']
    hgrepos = []
    issue_num = 8983
    keywords = ['patch']
    message_count = 7.0
    messages = ['107661', '107662', '107667', '107669', '107681', '107689', '114072']
    nosy_count = 5.0
    nosy_names = ['georg.brandl', 'mark.dickinson', 'belopolsky', 'eric.araujo', 'docs@python']
    pr_nums = []
    priority = 'normal'
    resolution = 'accepted'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue8983'
    versions = ['Python 2.7', 'Python 3.2']

    @abalkin
    Copy link
    Member Author

    abalkin commented Jun 12, 2010

    Inspired by issue bpo-8973, I did

    $ grep -in "see.*\.__doc__" Modules/*.c

    Surprisingly, there were not as many results as I feared.

    As I explained in the referenced issue,  "See name.__doc__", while technically correct, is not user friendly.  If you copy name.__doc__ to >>> prompt, you get an ugly repr of a multiline string.  I suggest s/name.__doc__/help(struct)/.

    Here are the grep results

    Modules/_threadmodule.c:904:Create a new lock object. See LockType.__doc__ for information about locks.");
    Modules/pwdmodule.c:103:See pwd.__doc__ for more on password database entries.");
    Modules/pwdmodule.c:124:See pwd.__doc__ for more on password database entries.");
    Modules/pwdmodule.c:155:See pwd.__doc__ for more on password database entries.");
    Modules/spwdmodule.c:111:See spwd.__doc__ for more on shadow password database entries.");
    Modules/spwdmodule.c:143:See spwd.__doc__ for more on shadow password database entries.");

    @abalkin abalkin added docs Documentation in the Doc dir type-feature A feature request or enhancement labels Jun 12, 2010
    @abalkin
    Copy link
    Member Author

    abalkin commented Jun 12, 2010

    A couple more:

    $ grep -in "see.*\.__doc__" Lib/*.py
    Lib/doctest.py:1782:    See doctest.__doc__ for an overview.
    Lib/inspect.py:162:    See isfunction.__doc__ for attributes listing."""

    an a really problematic

    Objects/typeobject.c:5529: "see x.__class__.__doc__ for signature",

    This affects every class' help and is very confusing when class doecstring does not show the constructor signature.

    @birkenfeld
    Copy link
    Member

    I agree, help(obj) is the better advice. Would you prepare a patch?

    @abalkin
    Copy link
    Member Author

    abalkin commented Jun 12, 2010

    Will do.

    @abalkin abalkin assigned abalkin and unassigned docspython Jun 12, 2010
    @abalkin
    Copy link
    Member Author

    abalkin commented Jun 12, 2010

    Attaching bpo-8983.diff patch. I am a bit unsure about __init__ docstring change:

    1. Are cases when help(type(x)) differs from help(x) important enough to distinguish in docstring?

    2. Do we need a default docstring on __init__ at all? If so, should we keep a reference to class doc which may not be correct? See bpo-8973.

    3. Why __init__ has a default docstring but __new__ and __del__ don't?

    4. There are some other inconsistencies in type docstrings. E.g., "__subclasschck__ -> check if an class is a subclass" (misspelling and and missing ()).

    @merwok
    Copy link
    Member

    merwok commented Jun 12, 2010

    1. For old-style class instances, both help(i) and help(type(i)) give the help for the instance type, which is highly unhelpful IMO. Otherwise it seems than both C class instances and regular Python new-style class instances give the class doc for help(i). Summary: help(x) is good, help(type(x)) unnecessary.

      1. Magic methods are documented through docs.python.org and eventually ABCs, not docstrings. I see no reason to make an exception for __init__, except if removing its docstring breaks code.
    2. There are actually two typos ;) Regarding parens, I personally think it’s not helpful to always put them, since e.g. “len()” is not valid, but my choice is not Python’s.

    @abalkin
    Copy link
    Member Author

    abalkin commented Aug 16, 2010

    Committed in r84106. I left the __init__ docstring issue unresolved because it is orthogonal to the name.__doc__ vs. help(name) issue here.

    With redundant help(type(x)), the meaning of the docstring is not changed. I am leaving docstrings on magic methods question for a separate issue.

    @abalkin abalkin closed this as completed Aug 16, 2010
    @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
    docs Documentation in the Doc dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants