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

optparse.OptionGroup with_statement context handling #46408

Closed
hoffman mannequin opened this issue Feb 21, 2008 · 5 comments
Closed

optparse.OptionGroup with_statement context handling #46408

hoffman mannequin opened this issue Feb 21, 2008 · 5 comments
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@hoffman
Copy link
Mannequin

hoffman mannequin commented Feb 21, 2008

BPO 2155
Nosy @birkenfeld, @srittau

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 2010-08-01.14:58:26.142>
created_at = <Date 2008-02-21.15:47:59.754>
labels = ['type-feature', 'library']
title = 'optparse.OptionGroup with_statement context handling'
updated_at = <Date 2010-08-01.14:58:26.140>
user = 'https://bugs.python.org/hoffman'

bugs.python.org fields:

activity = <Date 2010-08-01.14:58:26.140>
actor = 'georg.brandl'
assignee = 'gward'
closed = True
closed_date = <Date 2010-08-01.14:58:26.142>
closer = 'georg.brandl'
components = ['Library (Lib)']
creation = <Date 2008-02-21.15:47:59.754>
creator = 'hoffman'
dependencies = []
files = []
hgrepos = []
issue_num = 2155
keywords = ['patch']
message_count = 5.0
messages = ['62625', '64125', '77633', '77872', '112340']
nosy_count = 5.0
nosy_names = ['gward', 'georg.brandl', 'jafo', 'srittau', 'hoffman']
pr_nums = []
priority = 'normal'
resolution = 'rejected'
stage = None
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue2155'
versions = []

@hoffman
Copy link
Mannequin Author

hoffman mannequin commented Feb 21, 2008

Adding these four lines to optparse.OptionGroup makes using option
groups vastly easier:

    def __enter__(self):
        return self

    def __exit__(self, *exc_info):
        self.parser.add_option_group(self)

You can then do things like:

    with OptionGroup(parser, "Group name") as group:
        group.add_option(...)

@hoffman hoffman mannequin added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Feb 21, 2008
@jafo
Copy link
Mannequin

jafo mannequin commented Mar 19, 2008

Patch is inline.

@jafo jafo mannequin assigned gward Mar 19, 2008
@hoffman
Copy link
Mannequin Author

hoffman mannequin commented Dec 11, 2008

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.

@srittau
Copy link
Mannequin

srittau mannequin commented Dec 15, 2008

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")
group.add_option(...)
parser.add_option_group(group)

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.

@birkenfeld
Copy link
Member

I agree with Sebastian that this is not a good use for a context manager.

@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-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant