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

contextlib doc bug #73320

Closed
YoSTEALTH mannequin opened this issue Jan 2, 2017 · 7 comments
Closed

contextlib doc bug #73320

YoSTEALTH mannequin opened this issue Jan 2, 2017 · 7 comments
Labels
3.7 (EOL) end of life docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error

Comments

@YoSTEALTH
Copy link
Mannequin

YoSTEALTH mannequin commented Jan 2, 2017

BPO 29134
Nosy @orsenthil, @marco-buttu, @YoSTEALTH, @Kwpolska, @altendky
Files
  • contextlib.patch
  • 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 = None
    closed_at = <Date 2017-01-04.05:09:06.813>
    created_at = <Date 2017-01-02.16:54:11.677>
    labels = ['invalid', 'type-bug', '3.7', 'docs']
    title = 'contextlib doc bug'
    updated_at = <Date 2017-01-04.15:56:37.332>
    user = 'https://github.com/YoSTEALTH'

    bugs.python.org fields:

    activity = <Date 2017-01-04.15:56:37.332>
    actor = 'altendky'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2017-01-04.05:09:06.813>
    closer = 'orsenthil'
    components = ['Documentation']
    creation = <Date 2017-01-02.16:54:11.677>
    creator = 'YoSTEALTH'
    dependencies = []
    files = ['46116']
    hgrepos = []
    issue_num = 29134
    keywords = ['patch']
    message_count = 7.0
    messages = ['284489', '284491', '284495', '284496', '284497', '284609', '284644']
    nosy_count = 7.0
    nosy_names = ['orsenthil', 'SilentGhost', 'docs@python', 'marco.buttu', 'YoSTEALTH', 'Kwpolska', 'altendky']
    pr_nums = []
    priority = 'normal'
    resolution = 'not a bug'
    stage = 'patch review'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue29134'
    versions = ['Python 3.5', 'Python 3.6', 'Python 3.7']

    @YoSTEALTH
    Copy link
    Mannequin Author

    YoSTEALTH mannequin commented Jan 2, 2017

    Link: https://docs.python.org/3/library/contextlib.html#contextlib.ContextDecorator

    "from contextlib import ContextDecorator

    class mycontext(ContextBaseClass, ContextDecorator):"

    "ContextBaseClass" is referenced but its no where to be found in source.

    @SilentGhost
    Copy link
    Mannequin

    SilentGhost mannequin commented Jan 2, 2017

    ContextBaseClass is meant to represent a user-defined class that is a parent of mycontext.

    @marco-buttu
    Copy link
    Mannequin

    marco-buttu mannequin commented Jan 2, 2017

    Going a bit OT, in the contextlib doc there are two examples that have both normal code and shell code in the same code block. In this way we loose the prompt syntax highlight, and the code block can also confuse the reader. In the patch attached the two examples are executed entirely in the shell, and both are under doctest.

    @YoSTEALTH
    Copy link
    Mannequin Author

    YoSTEALTH mannequin commented Jan 2, 2017

    @SilentGhost
    You are right, I see it now!

    If this is the case maybe "ContextBaseClass" should be changed to "UserDefinedContextClass" (or something...) having "Base" in the class name was confusing, since module "io" has IOBase class that refer to its "base class" figured it was the same concept for contextlib as well.

    Also it would be nice if example was improved a bit.

    Another Idea:

    • why not have an empty context manager base class? like:

    def ContextBase:

        def __enter__(self):
            return self
    
        def __exit__(self, *errors):
            pass

    This is something anyone can use to extend their class to support context manager? I actually have a class like this i have used many times in my projects! Its simple yet useful.

    @YoSTEALTH
    Copy link
    Mannequin Author

    YoSTEALTH mannequin commented Jan 2, 2017

    typo:
    def ContextBase:
    to
    class ContextBase:

    @SilentGhost SilentGhost mannequin added docs Documentation in the Doc dir 3.7 (EOL) end of life labels Jan 3, 2017
    @SilentGhost SilentGhost mannequin assigned docspython Jan 3, 2017
    @SilentGhost SilentGhost mannequin added the type-bug An unexpected behavior, bug, or error label Jan 3, 2017
    @orsenthil
    Copy link
    Member

    I am going to vote for "not a bug" here. From the context is it understood that the ContextBaseClass is to be provided by the user.

    Existing context managers that already have a base class can be extended by using ContextDecorator as a mixin class:

    The idea here is the illustrate the Mixin possibility with a Base class and not to provide a full example with Base class code as well.

    @marco, also not a good ticket add more doc strings to this module.rst. If the docs of those can be improved, they can done separately, concentrating on all the possible improvements.

    @altendky
    Copy link
    Mannequin

    altendky mannequin commented Jan 4, 2017

    I would think that the idea of simply adding some reference to User such as was suggested with UserDefinedContextClass would be reasonable and helpful. This doesn't involve any more code merely a more explanatory name.

    @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
    3.7 (EOL) end of life docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant