Issue6535
Created on 2009-07-21 19:27 by mindvirus, last changed 2009-07-22 00:03 by r.david.murray.
| File name |
Uploaded |
Description |
Edit |
Remove |
|
optparse.py.diff
|
mindvirus,
2009-07-21 22:08
|
Optparse patch |
|
|
|
testcase.py
|
mindvirus,
2009-07-21 22:09
|
Test case |
|
|
|
msg90767 - (view) |
Author: Daniel Kaplun (mindvirus) |
Date: 2009-07-21 19:27 |
|
In the second example to allow usage of the required field for options,
it seems as if you already have all you need to implement the feature
into optparse. I modified it a bit to allow OptionGroups:
class Option(optparse.Option):
ATTRS = optparse.Option.ATTRS + ['required']
def _check_required(self):
if self.required and not self.takes_value():
raise OptionError(
"required flag set for option that doesn't take a value",
self)
# Make sure _check_required() is called from the constructor!
CHECK_METHODS = optparse.Option.CHECK_METHODS + [_check_required]
def process(self, opt, value, values, parser):
optparse.Option.process(self, opt, value, values, parser)
parser.option_seen[self] = 1
class OptionParser(optparse.OptionParser):
def _init_parsing_state(self):
optparse.OptionParser._init_parsing_state(self)
self.option_seen = {}
def check_values(self, values, args):
for option in self.option_list + sum((optiongroup.option_list for
optiongroup in self.option_groups), []):
if isinstance(option, Option) and option.required and not
self.option_seen.has_key(option):
self.error("%s not supplied" % (option, ))
return (values, args)
The question: why hasn't your existing example been merged with the
OptionParse code to allow the required field for options?
|
|
msg90773 - (view) |
Author: R. David Murray (r.david.murray) |
Date: 2009-07-21 20:44 |
|
Feature requests can only go into releases under development.
No guarantees, but if you want to give this a better chance of getting
in a patch against trunk including tests would be a minimum prerequisite.
Alternatively or in addition you could help review argparse for
inclusion into the stdlib (see issue 6247; I know the issue is closed
but it could still be moved forward if enough interest is expressed).
|
|
msg90777 - (view) |
Author: R. David Murray (r.david.murray) |
Date: 2009-07-21 22:57 |
|
What we are looking for in the way of tests is unit tests to add to
test_optparse. Another piece that I forgot about that we'll need is a
documentation patch.
Finally, it will be easier to review the patch if you don't make other
changes in the patch. Your PEP 8 changes are good in principle, but
they make it harder to review the patch.
|
|
msg90781 - (view) |
Author: Daniel Kaplun (mindvirus) |
Date: 2009-07-21 23:24 |
|
I have not a single clue how to unit test.
What do you mean by documentation patch? Do you want me to update the
documentation within the file to reflect changes?
|
|
msg90783 - (view) |
Author: R. David Murray (r.david.murray) |
Date: 2009-07-22 00:03 |
|
Well, if you get check out the current trunk via svn (as described in
the developer's faq linked from http://www.python.org/dev) and you look
at what Lib/test/test_optparse.py currently does, you might find it is
not too hard to add some new cases to test the new code. Then in
Doc/library/optparse.rst, you make appropriate changes to the
documentation RestructuredTest source code, and post everything in a
single patch.
If you don't want to do all this that's fine, the ticket will sit here
until someone comes along who wants to move it forward ;)
Thanks for taking an interest in this.
|
|
| Date |
User |
Action |
Args |
| 2009-07-22 00:03:22 | r.david.murray | set | messages:
+ msg90783 |
| 2009-07-21 23:24:44 | mindvirus | set | messages:
+ msg90781 |
| 2009-07-21 22:57:55 | r.david.murray | set | messages:
+ msg90777 |
| 2009-07-21 22:09:09 | mindvirus | set | files:
+ testcase.py |
| 2009-07-21 22:08:39 | mindvirus | set | files:
+ optparse.py.diff keywords:
+ patch |
| 2009-07-21 20:44:46 | r.david.murray | set | nosy:
+ r.david.murray versions:
- Python 2.6, Python 2.5, Python 2.4, Python 3.0, Python 3.1 messages:
+ msg90773 priority: normal components:
+ Library (Lib), - Extension Modules keywords:
+ easy stage: test needed |
| 2009-07-21 19:29:05 | mindvirus | set | type: feature request |
| 2009-07-21 19:27:47 | mindvirus | create | |
|