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

Add doc-string to UserDict and DictMixin #46425

Closed
abalkin opened this issue Feb 24, 2008 · 4 comments
Closed

Add doc-string to UserDict and DictMixin #46425

abalkin opened this issue Feb 24, 2008 · 4 comments
Assignees
Labels
docs Documentation in the Doc dir

Comments

@abalkin
Copy link
Member

abalkin commented Feb 24, 2008

BPO 2172
Nosy @rhettinger, @abalkin
Files
  • UserDict-doc.diff
  • UserDict-doc.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/rhettinger'
    closed_at = <Date 2008-03-24.08:53:20.351>
    created_at = <Date 2008-02-24.05:09:30.860>
    labels = ['docs']
    title = 'Add doc-string to UserDict and DictMixin'
    updated_at = <Date 2008-03-24.17:19:15.925>
    user = 'https://github.com/abalkin'

    bugs.python.org fields:

    activity = <Date 2008-03-24.17:19:15.925>
    actor = 'belopolsky'
    assignee = 'rhettinger'
    closed = True
    closed_date = <Date 2008-03-24.08:53:20.351>
    closer = 'rhettinger'
    components = ['Documentation']
    creation = <Date 2008-02-24.05:09:30.860>
    creator = 'belopolsky'
    dependencies = []
    files = ['9529', '9530']
    hgrepos = []
    issue_num = 2172
    keywords = ['patch']
    message_count = 4.0
    messages = ['62876', '62877', '64404', '64423']
    nosy_count = 2.0
    nosy_names = ['rhettinger', 'belopolsky']
    pr_nums = []
    priority = 'normal'
    resolution = 'rejected'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue2172'
    versions = ['Python 2.6']

    @abalkin
    Copy link
    Member Author

    abalkin commented Feb 24, 2008

    Attached patch improves pydoc UserDict presentation.

    One of the problems with the current documentation in comments is that
    order of methods is not preserved and thus the method level comments in
    DictMixin implementation are meaningless in pydoc. (In any case the
    comments are not accurate even in the source file.)

    If this patch is accepted in principle, the original level comments
    should be removed. I am leaving them intact to simplify the review.

    @abalkin
    Copy link
    Member Author

    abalkin commented Feb 24, 2008

    Fixed an error in lavels doc. Needs review.

    @abalkin abalkin added the docs Documentation in the Doc dir label Feb 24, 2008
    @rhettinger rhettinger self-assigned this Feb 24, 2008
    @rhettinger
    Copy link
    Contributor

    I'm not sure the class docstring approach is suitable for a mixin. It
    seems fine to me that pydoc strips the commentary on the mixin as a
    standalone class; instead it appropriately focuses on the client class
    that uses the mixin as part of its API.

    FWIW, all of this code goes away in Py3.0.

    @abalkin
    Copy link
    Member Author

    abalkin commented Mar 24, 2008

    On Mon, Mar 24, 2008 at 4:53 AM, Raymond Hettinger
    <report@bugs.python.org> wrote:

    I'm not sure the class docstring approach is suitable for a mixin. It
    seems fine to me that pydoc strips the commentary on the mixin as a
    standalone class;

    My main point was not that some commentary was stripped by
    pydoc, but that the commentary that is not stripped is misleading:

    The beginning of pydoc UserDict.DictMixin is rendered as follows:

    UserDict.DictMixin = class DictMixin
     |  Methods defined here:
     |
     |  __cmp__(self, other)
     |
     |  __contains__(self, key)
     |
     |  __iter__(self)
     |      # second level definitions support higher levels
     |
     |  __len__(self)
    ..

    What does "second level definitions support higher levels" comment
    below __iter__ means? Does it apply to all methods above or all
    methods below but above the "third level ..." comment or just to
    __iter__? All of these plausible interpretations are wrong.

    Furthemore, pydoc UserDict is rendered as follows:

    NAME
    UserDict - A more or less complete user-defined wrapper around
    dictionary objects.

    FILE
    /bnv/home/abelopolsky/Work/python-svn/trunk/Lib/UserDict.py

    CLASSES
    DictMixin
    UserDict
    IterableUserDict

    class DictMixin
    

    ...

    Which is not helpful at all in understanding of what DictMixin is for.

    instead it appropriately focuses on the client class
    that uses the mixin as part of its API.

    I assume you refer to UserDict as the "client class". In what sense
    does it use "mixin as part of its API"? In 2.x, UserDict does not
    derive from DictMixin. To the contrary, UserDict and DictMixin
    present quite different APIs to the users of derived classes. For
    example, overriding __getitem__ does not affect has_key,
    __contains__ or iter* methods of the class deriving from UserDict,
    which is different from the way DictMixin descendants work.

    .. that's why I selected version 2.6 when I submitted this issue. :-)

    However, AFAICT, not all this code goes away, just UserDict is
    moved to collections and DictMixin functionality is replaced with
    ABCs. This is a welcome change because with abstract
    methods the classes become self-documenting, but I have to
    note that UserDict will behave differently in 3.0: the following
    code print 1 in 2.x and 42 in 3.0:

    class X(UserDict):
        def __getitem__(self, _):
            return 42

    print(X(a=1).pop('a'))

    This change should probably be reflected in the docs
    somewhere.

    @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
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants