On Sep 11, 2012, at 01:17 PM, Terry Reedy wrote:
This second example strikes me (naively, as English speaker but not argparse user) as 'wrong' in that 'default' is being misused to mean 'start value that is always used to generate the final value' [as in sum(iterable, start=0)], rather than 'final value that is only used if nothing else is given' (as in nearly all uses of 'default' in Python). Perhaps this is what you meant by "semantic ambiguity".
Well, in a sense yes, that is an ambiguity so I won't quibble about whether it's the same one or not. :)
As I see it, storing is done *with* a default or explicit value, appending is done *to* a start value *with* whatever. Perhaps reusing 'default' instead of using a new name such as 'start' was a bit too clever for our own good ;-).
I suspect that it's too late to change this, by say adding a 'start' parameter or some such, at least until Python 3.4.
The fix for issue 12776 broke the last two lines of the second example, because in the no-command-line-arguments-given case, arg.test is the *string* "[]" and not the actual empty list object.
This seems even more wrong (as in slightly crazy) as it switches the meaning of 'default' within one parser example rather than between parser examples.
And yet, that's how it works in 2.7, 3.2, and 3.3.1.
It seems to me that the semantics could reasonably be implied to mean that the type converter should only be applied to the default value when action='store', as is the default. Then in the second example, because action='append', the type conversion would not be applied (it makes no sense to do so).
I arrive at the same conclusion, I believe, by saying that for a given parser, the type converter should always or never be applied to 'default', which should mean converting or not when the parser is created. Append to 'default as base or start' should mean not converting.
Does that mean that for fixing the regression, you favor applying the type conversion only for action='store' or by only applying it when the default is a string? It seems better to only apply the type conversion for action='store' but more backward compatible for the original behavior to only apply it when default is a string. Cheers, -Barry