<div dir="ltr"><div><div><div>I mean, it's definitely possible, but I'd argue that's actually not any more explicit - and, in fact, args.stuff = something(args.stuff) is arguably less explicit because it's just an arbitrary transform, rather than being called out as "this is the wrapper element for these args." <br><br>The places where I see doing transforms after as substantially worse than this:<br><br></div>1. any case where a single parser is being used in multiple scripts, or being extended. Moving this kind of thing out of the parser means the logic has to be replicated outside the parser everywhere it's called.<br></div>2. validation of multiple arguments against each other - once you're out of the parser, you have to write separate error handling code instead of just throwing the right exception.</div><div><br></div>- Dave<br><div><br><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Aug 4, 2017 at 12:33 PM, Brett Cannon <span dir="ltr"><<a href="mailto:brett@python.org" target="_blank">brett@python.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">I'm not a heavy argparse user so take my opinion with a grain of salt (and I do appreciate the time you put into proposing this), but I'm not seeing the usefulness to classify this as so pragmatic as to outweigh adding one more thing to explain about argparse. Since you're proposing just having a callable to use after constructing the list couldn't you just do e.g. `args.stuff = frozenset(args.stuff)` instead and just be explicit about it?</p>
<br><div class="gmail_quote"><div><div class="h5"><div dir="ltr">On Fri, Aug 4, 2017, 06:01 David Mayo, <<a href="mailto:pobocks@gmail.com" target="_blank">pobocks@gmail.com</a>> wrote:<br></div></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr"><div><div>A friend of mine (@bcjbcjbcj
on twitter) came up with an idea for an argparse improvement that I'd
like to propose for inclusion.
<br><br>Currently, argparse with nargs=<anything but None> collects
arguments into a list (or a list of lists in the case of
action="append"). I would like to propose adding a "collection type"
argument to the store and append actions and to add_argument,
consisting of a callable that would be applied to the list of
type-converted args before adding them to the Namespace. This would
allow for alternate constructors (e.g. set), for modifying the list
(e.g. with sorted), or to do checking of properties expected across all
components of the argument at parse time.
<br><br>I've worked up a set of examples in this gist: <a href="https://gist.github.com/pobocks/bff0bea494f2b7ec7eba1e8ae281b888" target="_blank">https://gist.github.com/<wbr>pobocks/<wbr>bff0bea494f2b7ec7eba1e8ae281b8<wbr>88</a><br><br>And a rough implementation here: <a href="https://github.com/python/cpython/compare/master...pobocks:argparse_colltype" target="_blank">https://github.com/python/<wbr>cpython/compare/master...<wbr>pobocks:argparse_colltype</a><br><br>I think this would be genuinely useful, and would require very little
change to argparse, which should be backwards compatible provided that
the default for the collection type is list, or None with list specified
if None.
<br><br>Thank you all for your time in considering this,
<br><br>- Dave Mayo<br></div>@pobocks on twitter, github, various others<br></div></div></div></div>
______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br>
</blockquote></div>
</blockquote></div><br></div>