This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: optparse.OptionGroup with_statement context handling
Type: enhancement Stage:
Components: Library (Lib) Versions:
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: gward Nosy List: georg.brandl, gward, hoffman, jafo, srittau
Priority: normal Keywords: patch

Created on 2008-02-21 15:47 by hoffman, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (5)
msg62625 - (view) Author: Michael Hoffman (hoffman) Date: 2008-02-21 15:47
Adding these four lines to optparse.OptionGroup makes using option
groups vastly easier:

    def __enter__(self):
        return self

    def __exit__(self, *exc_info):

You can then do things like:

    with OptionGroup(parser, "Group name") as group:
msg64125 - (view) Author: Sean Reifschneider (jafo) * (Python committer) Date: 2008-03-19 23:50
Patch is inline.
msg77633 - (view) Author: Michael Hoffman (hoffman) Date: 2008-12-11 22:05
Is there anything I can do to get this feature request considered
earlier? I can generate a real patch, but I figured that wouldn't
necessary for something so simple. This has the advantage that it can
probably be cut/pasted into any version of the code.
msg77872 - (view) Author: Sebastian Rittau (srittau) * Date: 2008-12-15 15:31
This API is too "magical" to my liking and doesn't really reflect what
context manager's are supposed to do, i.e. handling resources. Also, I
don't see much advantage over:

group = OptionGroup(parser, "Group name")

Finally, the __exit__ handler adds the option group to the parser in any
case, whether there was an exception raised inside the block or not.
msg112340 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-08-01 14:58
I agree with Sebastian that this is not a good use for a context manager.
Date User Action Args
2022-04-11 14:56:31adminsetgithub: 46408
2010-08-01 14:58:26georg.brandlsetstatus: open -> closed

nosy: + georg.brandl
messages: + msg112340

resolution: rejected
2008-12-15 15:31:01srittausetnosy: + srittau
messages: + msg77872
2008-12-11 22:05:21hoffmansetmessages: + msg77633
2008-03-19 23:50:51jafosetpriority: normal
assignee: gward
messages: + msg64125
keywords: + patch
nosy: + gward, jafo
2008-02-21 15:47:59hoffmancreate