paul j3 added the comment:
If we make this change to '_StoreAction', we need to do it to 4 other
subclasses which take the same 'setattr(namespace, self.dest, values)'.
An alternative would be to define a 'Namespace' function that does this
conditional 's
Changes by paul j3 :
--
nosy: +paul.j3
___
Python tracker
<http://bugs.python.org/issue9351>
___
___
Python-bugs-list mailing list
Unsubscribe:
https://mail.pyth
paul j3 added the comment:
In the attached file I tried another approach - a custom Action class. It
gives you the custom behavior now, instead of 2-3 releases in the future.
class Action2(Action):
# custom action
def __init__(self, *args, **kwargs):
super
paul j3 added the comment:
In http://bugs.python.org/issue11588#msg212243 I explore the option of using
decorators to 'register' custom functions with the parser. There I was adding
exclusive/inclusive tests, but the same approach could be used to register
custom types and a
paul j3 added the comment:
This is not getting much attention for several reasons:
- there's quite a backlog of argparse patches and issues
- 'set_defaults' is not commonly used. Setting default in 'add_argument' seems
more common.
- defining the same argumen
Changes by paul j3 :
--
nosy: +paul.j3
___
Python tracker
<http://bugs.python.org/issue12776>
___
___
Python-bugs-list mailing list
Unsubscribe:
https://mail.pyth
Paul Suh added the comment:
I found a repeatable, public test case:
http://www.macupdate.com/download/26915/ScreenFlow-4.5.1.dmg
Using urllib2 with the following code leads to a redirect loop:
#!/usr/bin/python
import urllib2
h = urllib2.HTTPHandler(debuglevel=1)
h2 = urllib2.HTTPSHandler
paul j3 added the comment:
I think is issue was already raised in
http://bugs.python.org/issue14074
argparse allows nargs>1 for positional arguments but doesn't allow metavar to
be a tuple
--
nosy: +paul.j3
___
Python tracke
paul j3 added the comment:
You can specify the 'formatter_class' when creating each subparser:
sp1=sp.add_parser('cmd1', formatter_class =
argparse.RawDescriptionHelpFormatter)
The 'add_parser' command is the one that passes a variety of **kwargs to
'A
paul j3 added the comment:
Another way to add an existing Action to a group is to modify the
'add_argument' method for the Group subclass. For example we could add this to
the _MutuallyExclusiveGroup class:
def add_argument(self, *args, **kwargs):
# allow adding a
paul j3 added the comment:
First, 'parse_intermixed_args' on stack is not relevant. It's from an
unreleased patch that we worked on.
What matters is the 'print_help', invoked probably with a '-h'.
The error message that normally specifies the problem arg
Paul Moore added the comment:
TBH, I don't think I ever took this any further. As noted, the earlier patches
fixed the failures I was hitting.
It looks like Python 3.4 now has *two* definitions of find_unused_port, in
test.test_support and in test.support. And test_asyncio and test_f
Changes by Paul Moore :
--
nosy: -pmoore
___
Python tracker
<http://bugs.python.org/issue8576>
___
___
Python-bugs-list mailing list
Unsubscribe:
paul j3 added the comment:
The ''_expand_help' method formats one action (argument) at a time, so it could
issue an error message that includes that action's name.
The disconnect that you noticed arises because your bad 'help' parameter wasn't
tested until i
paul j3 added the comment:
In http://bugs.python.org/file30010/nargswarn.patch adding the
'_expand_help(action)' line should test the help string (during add_argument).
def _check_argument(self, action):
# check action arguments
# focus on the arguments that
paul j3 added the comment:
http://bugs.python.org/issue21666
raises the possibility of testing the 'help' parameter in the same way. By
adding (to _check_argument):
# check the 'help' string
try:
self._get_formatter()._expand_help(action)
Paul Koning added the comment:
I created a fix for this. This also fixes a second issue in mock_open, which
is that readline() raises StopIteration at EOF rather than returning empty
strings. See attached diff.
(Is there a better procedure for submitting fixes?)
--
nosy: +pkoning
Paul Koning added the comment:
This is the corresponding patch to the test suite.
--
Added file: http://bugs.python.org/file35598/testwith.diff
___
Python tracker
<http://bugs.python.org/issue21
paul j3 added the comment:
I have developed a UsageGroup class that can implement nested 'inclusive'
tests. Using this, the original example in this issue could be coded as 3
groups, 2 mutually_exclusive and inclusive one.
parser = ArgumentParser(prog='PROG
paul j3 added the comment:
It's essentially the same issue as http://bugs.python.org/issue21666.
An error in the 'help' parameter is not caught until 'print_help' is called
(via 'parse_args').
A possible improvement is to test the 'help' string
New submission from Paul Koning:
The read_data iterator that supplies bits of read data when asked from
unittest.mock.mock_open is a class attribute. The result is that, if you
instantiate the class multiple times, that iterator is shared. This isn't
documented and it seems counterintu
paul j3 added the comment:
It should be easy to write a subclass of Action, or append Action, that does
what you want. It just needs a different `__call__` method. You just need a
way of identifying an default that needs to be overwritten as opposed to
appended to.
def __call__(self
Paul Upchurch added the comment:
For the concept of "reasonable", it should be noted that this behaviour will
affect code that works with reasonably sized sequences despite the largeness of
the parameter.
Consider an extremely large array. To work with such an array, one would
Paul A. added the comment:
On Sun, Nov 18, 2012 at 08:01:39PM +, Terry J. Reedy wrote:
> I should have added 'please try compiling 3.x to make sure it has the same
> problem' since configure might behave differently.
I'm fairly sure I did, that was quite a few mon
New submission from paul j3:
Argparse
15.4.5.1. Sub-commands
In the example:
>>> parser.parse_args(['--help'])
usage: PROG [-h] [--foo] {a,b} ...
positional arguments:
{a,b} sub-command help
a a help
b b help
optional arguments:
-h, --help show this he
Changes by paul j3 :
--
nosy: +paul.j3
___
Python tracker
<http://bugs.python.org/issue11708>
___
___
Python-bugs-list mailing list
Unsubscribe:
https://mail.pyth
Changes by paul j3 :
--
nosy: +paul.j3
___
Python tracker
<http://bugs.python.org/issue13824>
___
___
Python-bugs-list mailing list
Unsubscribe:
https://mail.pyth
Changes by paul j3 :
--
nosy: +paul.j3
___
Python tracker
<http://bugs.python.org/issue14365>
___
___
Python-bugs-list mailing list
Unsubscribe:
https://mail.pyth
Changes by paul j3 :
--
nosy: +paul.j3
___
Python tracker
<http://bugs.python.org/issue9694>
___
___
Python-bugs-list mailing list
Unsubscribe:
https://mail.pyth
paul j3 added the comment:
Another situation in which this MultiGroupHelpFormatter helps is when one or
more of the groups includes an optional positional.
The regular formatter moves all the positionals to the end, after the
optionals. This move could easily break up a mutually exclusive
paul j3 added the comment:
On a related point, the 'action.required' value is set differently for '?' and
'*' positionals.
if kwargs.get('nargs') not in [OPTIONAL, ZERO_OR_MORE]:
kwargs['required'] = True
if kwargs.get(
paul j3 added the comment:
This is a HelpFormatter function that takes a list of formatted actions, and
groups contiguous blocks of optional positional actions. It accounts for
optionals (via prefix_chars) and mutually exclusive groups.
Since it assumes 'parts' is a list, rather t
paul j3 added the comment:
In this patch I implement a FileContext class. It differs from FileType
in 2 key areas:
- it returns a 'partial(open, filename, ...)'
- it wraps '-' (stdin/out) in a dummy context protecting the file from closure.
The resulting argument is
paul j3 added the comment:
An alternative way to delay the file opening, is to return an instance that has
a `filename` attribute, and has an `open` method. This can be compactly added
to the `FileContext` that I defined in the previous patch. The `FileContext`
provides the `_ostest
paul j3 added the comment:
Steven's patch (subparse_optionals.diff) run with jakub's test case
(argparse_subparses_ambiguous_bug.py) works. But if the input string is
print(parser.parse_args('--foo baz'.split()))
produces
Namespace(cmd=None, foo='baz
paul j3 added the comment:
I think the correction to the problem that I noted in the previous post is to
return 'None, arg_string, None', rather than 'action, arg_string, None' in the
case where the action is found in a subparser.
This is what '_parse_optional'
paul j3 added the comment:
In the last patch, 'parser.scan = True' is needed to activate this fix. I left
that switch in for testing convenience.
--
___
Python tracker
<http://bugs.python.o
Changes by paul j3 :
Removed file: http://bugs.python.org/file31888/subparser_patch.diff
___
Python tracker
<http://bugs.python.org/issue14365>
___
___
Python-bugs-list m
paul j3 added the comment:
This the argparse patch as described in the previous post, along with
test_argparse tests.
For now the tests handle both subparser required cases and not required ones (
http://bugs.python.org/issue9253 ). While error messages can differ based on
this
New submission from Paul Moore:
The documentation for venv states that __VENV_NAME__ in scripts is replaced by
the name of the virtualenv. In fact, it is replaced by context.prompt, which is
the prompt, rather than the name.
The various activate scripts are not consistent with this behaviour
Paul Moore added the comment:
Cool. Patch attached (this fixes __VENV_NAME__ and implements __VENV_PROMPT__)
--
keywords: +patch
Added file: http://bugs.python.org/file31938/venv_prompt.patch
___
Python tracker
<http://bugs.python.org/issue19
New submission from Tymoteusz Paul:
What happens (and how to reproduce):
import base64
str = """GET
http://www.google.com.hk/search?q=hotels+near+airport&pws=1&igu=1&ip=0.0.0.0&safe=images&gl=CN&gll=39.913889,116.391667&near=china&hl=zh-CN
HTTP
paul j3 added the comment:
Looks like this behavior is intentional. This subclass adds a '%(default)s'
string to the help lines if:
if '%(default)' not in action.help:
if action.default is not SUPPRESS:
defaulting_nargs = [OPTIONAL, ZERO_OR_
Paul Moore added the comment:
How about simply adding a further sentence, something like:
"Where a class is being used conceptually as a callable (for example, context
managers), the naming convention for callables (lower_case_with_underscores)
should be followed."
Maybe also add
Paul Hawkins added the comment:
I ran into this bug the first time I needed nargs + in a tool.
I found of course that if the option with the nargs is followed by another
option before the positional arguments it will work as expected. But then the
help would have to point this out, and it
paul j3 added the comment:
parse_args() would see ['-foo', 'bar1,bar2,bar3', 'pos1', 'pos2']. The
splitting on space is done by the shell. So having your own code split
'bar1,bar2,bar3' is simplest. But that would be messed up if the user e
Paul Moore added the comment:
+1 on switching the wording in the overriding principle section to say "factory
function to class". Although the fact that I made that mistake reflects my
point that if I'm thinking of class->wrapper as an "internal change" then I'
Paul Moore added the comment:
I'm in favour of keeping it simple - "use your common sense" should be a
general guideline here (even though I know people's tastes differ, and that can
be a source of endless debate :-))
--
___
P
paul j3 added the comment:
When you add an argument, argparse creates an `Action`, and returns it. It
also places that action in various lists (e.g. parse._actions) and
dictionaries. A `remove_argument` function would have to trace and remove all
of those links. That's a non-trivial
paul j3 added the comment:
Just hang on the Action object that the `add_argument` returned, and change its
`help` attribute.
a = parser.add_argument('--foo', help='initial help')
a.help = 'new help'
If using a custom parser class and s
paul j3 added the comment:
`argparse.SUPPRESS` should do the trick. According to the documentation it can
be used with `default` and `help` parameters.
--
___
Python tracker
<http://bugs.python.org/issue19
paul j3 added the comment:
f.nargs = '?'
f.default = argparse.SUPPRESS
f.help = argparse.SUPPRESS
may be best set of tweaks to a positional Action `f`. In quick tests it
removes `f` from the help, suppresses any complaints about a missing string,
and does not put anyth
paul j3 added the comment:
http://stackoverflow.com/a/20167038/901925
is an example of using `_parser_class` to produce different behavior in the
subparsers.
parser = ArgumentParser()
parser.add_argument('foo')
sp = parser.add_subparsers(dest='cmd')
sp._pars
paul j3 added the comment:
`parse_args` just calls `parse_known_args`, and then raises an error if `rest`
is not empty. So it is `parse_known_args` that is doing the abbreviation
matching.
Abbreviation matching is done relatively early, when `_parse_known_args` first
loops through the
paul j3 added the comment:
For a programmer who needs to turn off this abbreviation matching now, a simple
solution is to subclass ArgumentParser:
class MyParser(ArgumentParser):
def _get_option_tuples(self, option_string):
return []
This could be the place to
paul j3 added the comment:
With a minor tweak to `argparse._is_mnrep()`, `nargs='{3}'` would also work.
This means the same as `nargs=3`, so it isn't needed. But it is consistent
with the idea of accepting Regular Expression syntax where it makes sense.
`nargs='{2,3}?&
paul j3 added the comment:
Here's a function that implements the format string:
def custom_help(template):
def usage(self):
formatter = self._get_formatter()
formatter.add_usage(self.usage, self._actions,
self._mutually_exclusive_g
paul j3 added the comment:
Another approach would be make the 'argparse' argument a 'switch' command, and
act on it after parsing. Roughly what I have in mind is:
parser.add_argument('--verbosity', dest='switch_verbosity,
action='store_tru
paul j3 added the comment:
This patch has a 'custom_help' which, with a default template, is compatible
with 'format_help' (i.e. it passes test_argparse). It also handles the sample
template in this issue.
Due to long line wrapping issues, the 'Usage: ' strin
paul j3 added the comment:
That original template can also be implemented with a customized 'format_help':
def custom_help(self):
formatter = self._get_formatter()
formatter.add_text('My Program, version 3.5')
formatter.add_usage(self.
paul j3 added the comment:
This patch accomplishes this task by adding a _PseudoGroup class to
_SubParsersAction. It's like the _ChoicesPseudoAction except that it maintains
its own _choices_actions list.
It takes advantage of the fact that formatter._format_actions is recursive whe
Paul A. added the comment:
I believe this problem has been gone since around 2.7.5, so can I close this
myself?
--
resolution: -> out of date
status: open -> closed
___
Python tracker
<http://bugs.python.org/i
Changes by paul j3 :
--
nosy: +paul.j3
___
Python tracker
<http://bugs.python.org/issue1859>
___
___
Python-bugs-list mailing list
Unsubscribe:
https://mail.pyth
paul j3 added the comment:
It will take a while to reconstruct the circumstances behind this issue. I
think I was working through some online class examples, working in the Eclipse
pydev environment. Currently I'm mostly working in linux, and not doing much
with multiprocessing. Looks
paul j3 added the comment:
I wonder if this patch is needed.
- there hasn't been discussion in 4 years
- In Steven's use case, a group without any arguments, the group does not show
up. A common example of an empty argument group, is a parser without any user
defined arguments
paul j3 added the comment:
I believe http://bugs.python.org/issue14174 with REMAINDER has its roots in the
same issue - parse_args tries to process as many positionals as it can at a
time, regardless of what's left in the argument strings.
The fix proposed here depends on the 2nd arg
Changes by paul j3 :
--
nosy: +paul.j3
___
Python tracker
<http://bugs.python.org/issue20554>
___
___
Python-bugs-list mailing list
Unsubscribe:
https://mail.pyth
New submission from Tymoteusz Paul:
I've recently ran into a problem with urellib.request.urlopen that it fails
against one website (that I've found so far). The website itself is working
fine, I can access its content with other libraries like requests, curl and
outside of python w
paul j3 added the comment:
Here's a possible solution to the problem (assuming there really is one):
- redefine REMAINDER so it matches a '((?:A[AO]*)?)' pattern (where O is a
string that looks like an optional flag, A an argument string). I've added the
condition that
Changes by Tymoteusz Paul :
--
versions: +Python 3.2
___
Python tracker
<http://bugs.python.org/issue21896>
___
___
Python-bugs-list mailing list
Unsubscribe:
paul j3 added the comment:
The documentation currently warns
https://docs.python.org/2/library/multiprocessing.html#windows
> Safe importing of main module
> Make sure that the main module can be safely imported by a new Python
> interpreter without causing unintended side effect
paul j3 added the comment:
Apart from sorting, `_get_kwargs` does little more than:
return [k for k in action.__dict__.items() if not k[0].startswith('_')]
That is, it's the `items()` of the 'public' attributes of the action (or
parser). Those attributes are
paul j3 added the comment:
In elsdoerfer's example, the '--' effectively ends the argument list for
'--ignore'. '--' are not allowed in the arguments of an optional (see the end
of '_get_nargs_pattern()').
Rather the problem is at the start of
paul j3 added the comment:
This patch modifies that '--' handling from 13922, removing '--' from PARSER
and REMAINDER if it is the first string:
if action.nargs not in [PARSER, REMAINDER]:
try:
arg_strings.remove('--')
paul j3 added the comment:
http://bugs.python.org/issue9571 proposes a refinement to this patch - drop the
'--' from PARSER and REMAINDER nargs if it is the 1st string.
--
___
Python tracker
<http://bugs.python.o
Changes by Paul Moore :
--
resolution: -> fixed
status: open -> closed
___
Python tracker
<http://bugs.python.org/issue9055>
___
___
Python-bugs-list
paul j3 added the comment:
This is a straight forward patch, modifying '_registry_get' to return 'default'
if it gets this 'TypeError'. 'test_argparse.py' has a testcase based on
jnothman's example. Temporarily it includes a skipped test that wo
paul j3 added the comment:
The issue here is how `textwrap` handles the non-breaking space. That's being
address here:
http://bugs.python.org/issue20491 textwrap: Non-breaking space not honored
Temporarily an `argparse` user can get around it with
`formatter_
paul j3 added the comment:
In this patch I added the '_()' localization to the '_VersionAction' default
'help'.
While this is a straight forward change, I haven't tested it. It does run
test_argparse.py, but that doesn't have any tests for localiz
paul j3 added the comment:
To put this issue in perspective:
- There's nothing in the documentation about nesting a mutually exclusive group
in an argument group.
- There are prominent notes in the documentation about MEGs not taking title
and description. The '_add_container_act
paul j3 added the comment:
This patch probably won't work with [parents]. see
http://bugs.python.org/issue16807
--
___
Python tracker
<http://bugs.python.org/i
paul j3 added the comment:
The subcommands grouping mechanism proposed in http://bugs.python.org/issue9341
probably does not work with [parents] either.
This _add_container_actions method is brittle. It has to know too much about
the structure of a parser and its groups. Any change to that
paul j3 added the comment:
Positionals with '*' are discussed in more detail in:
http://bugs.python.org/issue9625 - argparse: Problem with defaults for variable
nargs when using choices
http://bugs.python.org/issue16878 - argparse: positional args with nargs='*'
paul j3 added the comment:
The documentation patch here should note that a positional '*' string default
is not parsed (i.e. does not pass through _get_value).
(see http://bugs.python.org/issue17250)
--
___
Python tracker
<http://bu
paul j3 added the comment:
The latest patch, using _shutil.get_terminal_size(), looks fine.
It lets environ['COLUMNS'] have priority over the end user's terminal width, as
demonstrated by the change to test_argparse. test_argparse doesn't test
changing the actual
paul j3 added the comment:
I suspect fixing this isn't going to be easy.
Extra lines are removed by the top most `formatter` function:
def format_help(self):
help = self._root_section.format_help()
if help:
help = self._long_break_matcher.sub('\
paul j3 added the comment:
A user could preserve blank lines by including a space (or more) in each. That
is, instead of ending with '\n', end with '\n \n'.
epilog = 'Epilog: No wrap text %(prog)s\n\tNext line\n \n'
---
I just checked a simple hel
paul j3 added the comment:
As Steven notes, the patch lacks tests. It also lacks documentation.
The 2 things that this class does different from 'version' are
- write without passing the text through 'textwrap'
- write to a user defined file
There is a difference in opin
paul j3 added the comment:
I think you want to unlink 9ac347a7f375.diff
It's from a different project
--
___
Python tracker
<http://bugs.python.org/is
New submission from paul j3:
A number of the issues seek to customize the wrapping behavior in HelpFormatter
- beyond what the current Formatter subclasses offer.
http://bugs.python.org/issue13923 and http://bugs.python.org/issue12806 - want
a wrapping method that preserves existing \n, while
paul j3 added the comment:
One way of marking a string for special wrap handing is to make it an instance
of a subclass of 'str'.
This patch adds class _WhitespaceStyle(str), and 5 subclasses corresponding to
the possible values of the CSS whitespace:.
Normal
Pre
New submission from Paul Moore:
It would be useful for shutil.rmtree to have a "force" argument that overrode
read-only permission issues, essentially replicating the behaviour of the -f
flag in rm -rf (Unix) and the -force parameter of del (Windows Powershell).
It's poss
Paul Moore added the comment:
Doh. And I was even involved in the previous issue. Sorry for the noise.
--
___
Python tracker
<http://bugs.python.org/issue22
paul j3 added the comment:
For now the user could add this to his module:
import os, shutil
os.environ['COLUMNS'] = str(shutil.get_terminal_size().columns)
--
___
Python tracker
<http://bugs.python.o
paul j3 added the comment:
Note that
'-t 1 2 3'.split()
becomes
['-t', '1', '2', '3']
Your 'type' function sees those 3 strings individually. Try printing 'string'
the first
paul j3 added the comment:
That's an artifact of how the group usage is formatted (which isn't very
robust). It's not designed to handle nested groups.
Mutually exclusive groups aren't meant to nest inside other mutually exclusive
groups. While it possible,
paul j3 added the comment:
On further thought, I think
group2 = group1.add_mutually_exclusive_group()
should have raised an error, stating that a group (argument or mutually
exclusive) cannot be added to a mutually exclusive group.
Also an argument group should not be added to another
paul j3 added the comment:
Here's a preliminary patch that raises an error if there's an attempt to nest a
mutually exclusive group in another, or there's an attempt to add an argument
group to either kind of group.
It still needs test_argparse.py and argparse.rst changes
paul j3 added the comment:
What you want is a custom Action rather than a custom Type.
from the documentation:
>>> class FooAction(argparse.Action):
... def __call__(self, parser, namespace, values, option_string=None):
... print('%r %r %r' %
paul j3 added the comment:
ArgumentGroups and MutuallyExclusiveGroups, as currently defined, won't give
you that kind of usage. I have appended a script that uses UsageGroups, which
I am developing for http://bugs.python.org/issue11588,
to solve this.
It defines 2 'mxg' grou
1901 - 2000 of 3046 matches
Mail list logo