This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author paul.j3
Recipients Sworddragon, paul.j3, r.david.murray
Date 2015-10-06.21:03:02
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1444165382.95.0.0877495504724.issue25308@psf.upfronthosting.co.za>
In-reply-to
Content
What you are asking about is the fact that different arguments can share a 'dest'.

https://docs.python.org/3/library/argparse.html#dest

The 'append_const' action has an example of shared 'dest'.  It says:

    The 'append_const' action is typically useful when multiple    
    arguments need to store constants to the same list. 

I've suggested 'dest' sharing in some SO questions.

Shared 'dest' may be a nuisance in the case of regular 'store' actions, since only the last value is retained.  But that also happens if a user repeats an argument.  Usually errors like this become apparent during development testing, and can be easily fixed with changes to the 'dest' parameter.

The 'conflict handler' mechanism does prevent conflicts in the option strings.  But it does not check the 'dest'.  In fact the parser does not maintain a list or dictionary of 'dest'.  It looks that up on the Actions as needed.

A simple function that would collect actions by 'dest' could use:

     dd = collections.defaultdict(list)
     for a in parser._actions:
         dd[a.dest].append(a)

Or the developer could collect their own list of Actions.  So it is easy to test for repeated 'dest', but I don't think it is generally needed or useful.

Custom Action classes can also be used to test for repeat assignments to a given 'dest' (objecting, for example, if the existing value in the Namespace is not the default).
History
Date User Action Args
2015-10-06 21:03:03paul.j3setrecipients: + paul.j3, r.david.murray, Sworddragon
2015-10-06 21:03:02paul.j3setmessageid: <1444165382.95.0.0877495504724.issue25308@psf.upfronthosting.co.za>
2015-10-06 21:03:02paul.j3linkissue25308 messages
2015-10-06 21:03:02paul.j3create