paul j3 added the comment:
When I apply `prog3.diff` to my 3.5.0dev, and run
python3 -m unittest Lib/test/test_argparse.py
I get 2 failures, both over 'usage: python3 -m [unit]test'.
It also fails with
python3 test_argparse.py
I suspect it would also fail if I ran the
paul j3 added the comment:
In argparse.py, I would put a utility function like `_prog_name` near the start
in the 'Utility functions and classes' block.
In test_argparse.py, I don't see the purpose of the `progname` changes in the
TestParentParsers class. That class wasn
paul j3 added the comment:
This assertion has triggered several bug issues, either due to an empty group
like this, or certain characters in the metavars.
http://bugs.python.org/issue17890
'argparse: mutually exclusive groups full of suppressed args can cause
AssertionErrors
paul j3 added the comment:
One way to reduce the testing burden, and to be extra safe regarding backward
compatibility is to make this action optional, rather than the default.
For example, make `_prog_name` importable (i.e. change the name), and then
expect the user to use it explicitly with
New submission from paul j3:
When there's a conflict involving an argument that was added via 'parents', and
the conflict handler is 'resolve', the action in the parent parser may be
damaged, rendering that parent unsuitable for further use.
In this example, 2 parent
paul j3 added the comment:
'sample3.py' contains a '_handle_conflict_parent' function.
With the help of a change in '_add_container_actions' it determines whether a
conflicting action occurs in multiple parsers (and argument_groups). If it
does, it deletes it f
Changes by paul j3 :
Added file: http://bugs.python.org/file36648/sample3.py
___
Python tracker
<http://bugs.python.org/issue22401>
___
___
Python-bugs-list mailin
Changes by paul j3 :
Removed file: http://bugs.python.org/file36635/sample3.py
___
Python tracker
<http://bugs.python.org/issue22401>
___
___
Python-bugs-list mailin
Changes by paul j3 :
Added file: http://bugs.python.org/file36656/sample3.py
___
Python tracker
<http://bugs.python.org/issue22401>
___
___
Python-bugs-list mailin
Changes by paul j3 :
Removed file: http://bugs.python.org/file36648/sample3.py
___
Python tracker
<http://bugs.python.org/issue22401>
___
___
Python-bugs-list mailin
paul j3 added the comment:
Your patch fails:
python3 -m unittest test_argparse.TestEmptyAndSpaceContainingArguments
specifically these 2 subcases:
(['-a badger'], NS(x='-a badger', y=None)),
(['-y', '-a badger'], NS(x=None, y='-a
Changes by paul j3 :
--
nosy: +bethard
___
Python tracker
<http://bugs.python.org/issue22401>
___
___
Python-bugs-list mailing list
Unsubscribe:
https://mail.pyth
Changes by paul j3 :
Added file: http://bugs.python.org/file36674/example.py
___
Python tracker
<http://bugs.python.org/issue22433>
___
___
Python-bugs-list mailin
Changes by paul j3 :
Removed file: http://bugs.python.org/file36672/example.py
___
Python tracker
<http://bugs.python.org/issue22433>
___
___
Python-bugs-list mailin
paul j3 added the comment:
Proposed patches like this are supposed to be generated against the current
development version (3.5...), especially if they are 'enhancements' (as opposed
to bugs). But there isn't much of a difference in argparse between 2.7+ and
3.4+ (except o
paul j3 added the comment:
I've added a patch with tests that I think handles this case, without messing
with existing test cases. It adds a new 'space' test right before the existing
one, one that explicitly handles an '=' arg_string.
If the space is in the 1s
paul j3 added the comment:
A 'store_true' action takes 0 arguments. In effect `nargs=0`.
With an `optional` (flagged) argument, the default `False` is used if the flag
is absent, and set to `True` when the flag is encountered (its Action
`__call__` function is run).
A `posi
Changes by paul j3 :
Added file: http://bugs.python.org/file36728/sample3.py
___
Python tracker
<http://bugs.python.org/issue22401>
___
___
Python-bugs-list mailin
Changes by paul j3 :
Removed file: http://bugs.python.org/file36656/sample3.py
___
Python tracker
<http://bugs.python.org/issue22401>
___
___
Python-bugs-list mailin
paul j3 added the comment:
If the empty argument group has a 'description' it is displayed. For example
with positionals group that I mentioned earlier:
parser = argparse.ArgumentParser()
parser._action_groups[0].description = 'test'
parser.print_help()
paul j3 added the comment:
A simpler solution is to make a copy of each Action when importing a parent
parser. The current practice is to just copy references. With a copy, an
Action will belong to only one group and parser, and the 'resolve' handler will
operate without problem
paul j3 added the comment:
Normally the unix shell takes care of this expansion. If I call a simple
script that prints sys.argv and runs a simple parser, I get:
2135:~/mypy$ python2.7 filetypetest.py ~/mypy/test.txt
['filetypetest.py', '/home/paul/mypy/test.txt'
paul j3 added the comment:
In argparse.py the status of ArgumentTypeError is ambiguous.
ArgumentError is listed as a public class, ArgumentTypeError is not. It also
says 'All other classes in this module are considered implementation details.'
ArgumentTypeError is a subclass of
paul j3 added the comment:
As Steven pointed out, the existing `add_argument_group` mechanism can be used
to group required arguments. For example
- temp.py --
parser = argparse.ArgumentParser(description = 'Do something')
paul j3 added the comment:
The attached file shows how the default argument groups could be redefined,
using 'required' as the criteria.
I've implemented it as a method that is added to a subclass of ArgumentParser.
This method is invoked after arguments are defined, prior to
paul j3 added the comment:
Here's another possible solution: add a `help_groups` parameter to
ArgumentParser. It is a list of base argument group names.
`parser.add_argument(...)' places the action in one of those groups.
This is a generalization of the current code which creates
Changes by paul j3 :
Added file: http://bugs.python.org/file34074/alt_grouping2.py
___
Python tracker
<http://bugs.python.org/issue9694>
___
___
Python-bugs-list mailin
paul j3 added the comment:
This patch corrects the handling of `seen_non_default_action` in another case -
a positional with '?' and `type=int` (or other conversion).
if
parser.add_argument('badger', type=int, nargs='?', default=2) # or '2'
and the
paul j3 added the comment:
The suggestion in this issue is to add a 'mutually_inclusive_group' mechanism,
one that would let users specify that certain sets of arguments must occur
together. Furthermore there was mention of allowing some sort of nesting.
Modeling
paul j3 added the comment:
Regarding a usage line like:
(-o FILE | (-O DIR & (-p PATTERN | -s SUFFIX))
The simplest option is to just a custom written 'usage' parameter.
With the existing HelpFormatter, a nested grouping like this is next to
impossible. It formats the argu
paul j3 added the comment:
This patch uses:
tests = self._registries['cross_tests'].values()
to get a list of functions to run at the end of '_parse_known_args'.
I replaced all of the mutually_exclusive_group tests (3 places) in the
ArgumentParser with a static funct
paul j3 added the comment:
This is an example of using 'patch_w_mxg2.diff' to handle the inclusive group
case proposed by the OP.
Since 'seen_non_default_actions' (and 'seen_actions') is a set of 'Actions', it
is convenient to use 'set' meth
paul j3 added the comment:
http://stackoverflow.com/questions/11455218
python, argparse: enable input parameter when another one has been specified
$ python myScript.py --parameter1 value1
$ python myScript.py --parameter1 value1 --parameter2 value2
$ python myScript.py --parameter2
paul j3 added the comment:
The addition of a simple decorator to the 'ArgumentParser' class, would
simplify registering the tests:
def crosstest(self, func):
# decorator to facilitate adding these functions
name = func.__name__
self.register('cro
paul j3 added the comment:
In http://bugs.python.org/issue11588 (Add "necessarily inclusive" groups to
argparse) I propose a generalization to these testing groups that would solve
your 'conflicter' case as follows:
usage = 'prog [ --conflicter | [ --opt1 ]
paul j3 added the comment:
I need to tweak the last patch so 'using_default' is also set when an
"nargs='*'" positional is set to the '[]' default.
if action.default is not None:
value = action.default
+
paul j3 added the comment:
A couple more thoughts on an expanded argument testing mechanism:
- do we need both 'seen_actions' and 'seen_non_default_actions'?
'seen_actions' is used only to test whether all required actions have been
seen. These 2 sets
paul j3 added the comment:
I might accept a patch that tweaks the ArgumentDefaultsHelpFormatter class, but
adding a parameter that must propagate through all the Action classes in just
plain wrong.
Users are confused by the many Action parameters as it is. And based on
StackOverFlow
Changes by paul j3 :
--
nosy: +paul.j3
___
Python tracker
<http://bugs.python.org/issue27153>
___
___
Python-bugs-list mailing list
Unsubscribe:
https://mail.pyth
Changes by paul j3 :
--
priority: normal -> high
___
Python tracker
<http://bugs.python.org/issue14156>
___
___
Python-bugs-list mailing list
Unsubscrib
paul j3 added the comment:
Yes, the information that `add_argument` returns a Action object is missing
from the documentation. It might be useful addition.
The documentation has many faults. It isn't basic enough to be a tutorial, but
many first time users use it as such, and get con
paul j3 added the comment:
The problem with the argparse backlog is that the original author of the module
is too busy with other things. And no one has stepped into his shoes. There
are people with experience in apply patches, and people who know the argparse
code well, but few, if any
Changes by paul j3 :
--
priority: normal -> high
___
Python tracker
<http://bugs.python.org/issue11874>
___
___
Python-bugs-list mailing list
Unsubscrib
paul j3 added the comment:
The problem with Python2.7 is that 'open' does not take 'closefd', or any of
the other parameters that were added for Python3.
open(name[, mode[, buffering]])
'rb' may make a difference on Py2 on Windows, but I haven't done any
paul j3 added the comment:
I've copied 'dbldash.patch' over from http://bugs.python.org/issue13922. I
mistakenly added it to a closed issue.
The patch is old, and should be revised. It is also missing tests for this
'--opt=--' case, even though it solves it.
I
paul j3 added the comment:
Here's the method in HelpFormatter that creates the metavar:
def _metavar_formatter(self, action, default_metavar):
if action.metavar is not None:
result = action.metavar
elif action.choices is not None:
choice_strs =
paul j3 added the comment:
subparsers is an example of choices displaying as the metavar. From the
documentation example:
usage: PROG [-h] [--foo] {a,b} ...
positional arguments:
{a,b} sub-command help
-
To the main parser, the 'subparser' is a positional argu
Changes by paul j3 :
--
nosy: +paul.j3
___
Python tracker
<http://bugs.python.org/issue14392>
___
___
Python-bugs-list mailing list
Unsubscribe:
https://mail.pyth
Changes by paul j3 :
--
nosy: +paul.j3
___
Python tracker
<http://bugs.python.org/issue9182>
___
___
Python-bugs-list mailing list
Unsubscribe:
https://mail.pyth
Changes by paul j3 :
--
nosy: +paul.j3
___
Python tracker
<http://bugs.python.org/issue14102>
___
___
Python-bugs-list mailing list
Unsubscribe:
https://mail.pyth
Changes by paul j3 :
--
priority: normal -> high
___
Python tracker
<http://bugs.python.org/issue9625>
___
___
Python-bugs-list mailing list
Unsubscrib
Changes by paul j3 :
--
priority: normal -> high
___
Python tracker
<http://bugs.python.org/issue9338>
___
___
Python-bugs-list mailing list
Unsubscrib
paul j3 added the comment:
Recent StackOverFlow question related to this issue
http://stackoverflow.com/questions/41750896/python-argparse-type-inconsistencies-when-combining-choices-nargs-and-def/41751730#41751730
--
___
Python tracker
<h
paul j3 added the comment:
Recent StackOverFlow question related to this issue - where the following
positional is a subparsers.
http://stackoverflow.com/questions/41742205/how-to-argparse-with-nargs-and-subcommands
--
___
Python tracker
<h
paul j3 added the comment:
http://bugs.python.org/issue9253 argparse: optional subparsers
Initially this bug/issue was a request to allow subparsers to be optional. But
with the change in how required actions are handled, subparsers are now
optional by default.
As you learned from the SO
Changes by paul j3 :
--
priority: normal -> high
___
Python tracker
<http://bugs.python.org/issue14074>
___
___
Python-bugs-list mailing list
Unsubscrib
paul j3 added the comment:
An alternative fix is to disallow tuple metavars for positionals.
A tuple metavar may look nice in the usage. But a well selected dest seems
better in the help line, and error messages. Using dest in all 3 roles, as we
do now, is the simplest compromise
paul j3 added the comment:
I propose closing this with reference to http://bugs.python.org/issue11588
--
status: open -> closed
___
Python tracker
<http://bugs.python.org/issu
paul j3 added the comment:
Another issue requesting a 'mutually dependent group'
http://bugs.python.org/issue23298
--
___
Python tracker
<http://bugs.python.o
paul j3 added the comment:
I'm proposing closing this with reference to http://bugs.python.org/issue22047
That focuses on the issue of adding mutually exclusive group to another
exclusive group, but adding Argument Group has the same problems.
Solutions, short of the big
paul j3 added the comment:
A similar issue about nesting an Argument Group inside a Mutually Exclusive
Group.
http://bugs.python.org/issue24736
--
___
Python tracker
<http://bugs.python.org/issue22
paul j3 added the comment:
http://bugs.python.org/issue22047 "argparse improperly prints mutually
exclusive options when they are in a group"
is similar.
-
There are two issues:
- the nesting of mutually exclusive groups
- the formatting of the usage in such cases.
Both ha
paul j3 added the comment:
We need to see the parser setup as well. I've never seen a bug like this
before. The `usage` line suggests that you are using subparsers.
It might be better if you asked this on StackOverFlow with a repeatable code
example. That's a better place to get
paul j3 added the comment:
I played around with the patch 117. I was wrong in thinking this was another
case of excess brackets being wrongly purged. The fix works by adding ending ]
that were missing the original. And it does add a symmetry to the code.
But it is easy to construct a set
Changes by paul j3 :
--
nosy: +paul.j3
___
Python tracker
<http://bugs.python.org/issue29632>
___
___
Python-bugs-list mailing list
Unsubscribe:
https://mail.pyth
paul j3 added the comment:
Those strings are defined in a 'parser.registry' dictionary, with expressions
like
self.register('action', 'store', _StoreAction)
(Users can also register their own custom classes. The registry can also be
used for the 'type&
paul j3 added the comment:
Earlier issue on the same topic - passing a mutually exclusive group via parents
http://bugs.python.org/issue16807
Can they be consolidated?
--
___
Python tracker
<http://bugs.python.org/issue25
paul j3 added the comment:
The PR117 patch adds an apparent symmetry. There's a if/else for 'start', so
shouldn't there also be one for 'end'?
if start in inserts:
inserts[start] += ' ['
else:
inserts[start] = '['
paul j3 added the comment:
I should probably give PR 120 more credit. By checking the group's container
it in effect eliminates this overlapping action problem. Nested groups aren't
used in the usage, just the union xor.
Maybe the question is, which is better for the user? To te
Changes by paul j3 :
--
stage: -> resolved
status: open -> closed
___
Python tracker
<http://bugs.python.org/issue29626>
___
___
Python-bugs-list
paul j3 added the comment:
With this setup
import argparse
parser=argparse.ArgumentParser(prog='cli')
parser.add_argument('nodes')
sp=parser.add_subparsers()
p1 = sp.add_parser('list', description='Lists nodes in your current project')
p1.add_argument(
paul j3 added the comment:
This help looks normal:
1427:~/mypy/argdev$ python3 issue29626.py delete -h
usage: cli delete [-h] [-p] userid
Deletes a user in your organization.
positional arguments:
userid The userid of user.
optional arguments:
-h, --help show this
paul j3 added the comment:
Sorry, I missed that. For some reason I looking something bigger.
That's coming from the `metavar=""'.
If I specify `metavar="xxx" that help line will have
-p xxx, --projectid xxx
Replace the 'xxx` with '', and yo
Changes by paul j3 :
--
status: closed -> open
___
Python tracker
<http://bugs.python.org/issue29626>
___
___
Python-bugs-list mailing list
Unsubscrib
paul j3 added the comment:
My answer to
http://stackoverflow.com/questions/23349349/argparse-with-required-subparser
is getting a slow but steady stream of + scores; so the `required subparser`
issue is still bothering people.
This particular question addresses the problem that the error
paul j3 added the comment:
There are 2 issues here -
- how to make the 'choices' list most compact
- how to make the multiple option strings display (long and short) more
compact, regardless of why the argument part is long.
When the choices display is too long, 'meta
paul j3 added the comment:
http://stackoverflow.com/questions/18275023/dont-show-long-options-twice-in-print-help-from-argparse
Once answer demonstrates how to change the Formatter:
class CustomHelpFormatter(argparse.HelpFormatter):
def _format_action_invocation(self, action):
if
Changes by paul j3 :
--
status: open -> closed
___
Python tracker
<http://bugs.python.org/issue24419>
___
___
Python-bugs-list mailing list
Unsubscrib
Changes by paul j3 :
--
nosy: +paul.j3
___
Python tracker
<http://bugs.python.org/issue8538>
___
___
Python-bugs-list mailing list
Unsubscribe:
https://mail.pyth
Changes by paul j3 :
--
nosy: +paul.j3
___
Python tracker
<http://bugs.python.org/issue12713>
___
___
Python-bugs-list mailing list
Unsubscribe:
https://mail.pyth
paul j3 added the comment:
I haven't read the discussion in full, but it looks like this patch was added
without any recent discussion or testing.
Previously if we had `choices=['a','abc']`, any exact match would be accepted,
and partial matches rejected. With th
paul j3 added the comment:
This error is also produced by
help = ' '
that is, a help line with all blanks. As long as there is a nonblank character
in the help line it format fine.
This issue doesn't need to be resolved by itself, but should be considered if
and when th
paul j3 added the comment:
Another failure case:
parser.add_argument('--int', type=int, choices=[10,15,25])
'--int 15` puts 'int=15' in the Namespace.
'--int 2' puts 'int=2' in the Namespace, because it matches the 'str(25)'.
'--i
New submission from paul j3:
The production argparse applies the type conversion to a string default whether
it is needed or not. With the 12776 and 15906 patch, that conversion is
postponed, so that it is applied only once. However, for a positional argument
with nargs='*', that
paul j3 added the comment:
If nargs=2, type=float, an argv like '1e4 -.002' works, but '1e4 -2e-3'
produces the same error as discussed here. The problem is that
_negative_number_matcher does not handle scientific notation. The proposed
generalize matcher, r'^-.+
paul j3 added the comment:
We need to be careful about when or where _negative_number_match is changed.
"
We basically do:
parser = argparse.ArgumentParser(...)
parser._negative_number_matcher = re.compile(r'^-.+$')
"
This changes the value for the parser itself, bu
paul j3 added the comment:
While
parser._negative_number_matcher
is used during parser.parse_args() to check whether an argument string is a
'negative number' (and hence whether to classify it as A or O).
parser._optionals._negative_number_matcher
is used during parser.add_arg
paul j3 added the comment:
I think the `re.compile(r'^-.+$')` behavior could be better achieved by
inserting a simple test in `_parse_optional` before the
`_negative_number_matcher` test.
# behave more like optparse even if the argument looks like a opt
paul j3 added the comment:
This patch makes two changes to argparse.py ArgumentParser._parse_optional()
- accept negative scientific and complex numbers
- add the args_default_to_positional parser option
_negative_number_matcher only matches integers and simple floats. This
is fine for
paul j3 added the comment:
Glenn
I looked at your t18a.py test case
parser = ArgumentParser()
parser.add_argument('--foo', dest='foo')
parser.add_argument('--bar', dest='bar')
parser.add_argument('foz')
parser.add_argument(&
paul j3 added the comment:
The 'args=' parameter is the same as the first positional parameter used in
most of the examples. That is normal Python behavior.
15.4.4.5. Beyond sys.argv
explains this alternative way of specifying argv.
Still 2 bullet points could be added to 15.4.4.
paul j3 added the comment:
This patch to argparse.rst adds the argument points to parse_args().
It also adds two points to the 'Upgrading optparse code' section, one about
using 'nargs=argparse.REMAINDER', and other about 'parse_known_args()'.
I'm not en
paul j3 added the comment:
I changed the reference to the optparse allow_interspersed_args attribute to
the disable_interspersed_args() method.
--
Added file: http://bugs.python.org/file29662/remainder.patch
___
Python tracker
<h
paul j3 added the comment:
The optparse page gives a reason for disable_interspersed_args():
"Use this if you have a command processor which runs another command which has
options of its own and you want to make sure these options don’t get confused.
For example, each command might h
paul j3 added the comment:
The test file, test_argparse.py, has a test case for this:
'class TestOptionalsActionAppendWithDefault'
argument_signatures = [Sig('--baz', action='append', default=['X'])]
successes = [
paul j3 added the comment:
Oops, I was wrong about this:
"Argparse doesn't prohibit all interspersed positionals. You could, for
example, have one or more positionals with other nargs that could be
interspersed. But the REMAINDER one has to be last."
parser.
paul j3 added the comment:
Looking further at test_argparse.py, I should say that the behavior of multiple
positionals when there is one cluster of positional argstrings is well
illustrated in the tests. It's the behavior when there are multiple clusters
(interspersed positionals) tha
paul j3 added the comment:
There are several problems with the patch provided in msg156315
This description:
"Added patch so that only the first '--' is removed by an argparse.PARSE or
argparse.REMAINDER argument."
should read
"Added patch so that only the first
paul j3 added the comment:
There's another 'feature' to the patch proposed here. It only deletes the
first '--' in the list of strings passed to '_get_values' for a particular
action.
parser = argparse.ArgumentParser()
parser.add_argument('fo
paul j3 added the comment:
I am working on an alternative solution that moves the '--' removal to the
consume_positionals() method, and only does it if there is a corresponding '-'
in the arg_strings_pattern.
--
___
P
501 - 600 of 778 matches
Mail list logo