Message228137
| Author |
paul.j3 |
| Recipients |
bethard, docs@python, paul.j3 |
| Date |
2014年10月01日.22:56:06 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1412204167.18.0.738196184941.issue22401@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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 problems.
In the attached patch, I added a `.copy` method to Action. I believe '.option_strings' is the only attribute that needs special handling, since it is a list, and 'resolve' operates on it. The other attributes are strings, or objects that the user defines (e.g. 'default', 'choices').
The other change is in '_add_container_actions', the method which imports parents. Here I make the copy action contingent on a 'action_copy' attribute of the conflict handler object (a function). I also define this attribute for the 'resolve' handler. I've made this copy contingent just to be safe w/r to backward compatibility, even though, I can't think of a reason for preferring the existing copy by reference.
In another Stackoverflow question, a poster wanted to use the same parent for 2 subparsers, but give the 2 actions different defaults. This copy approach solves that issue.
This patch needs testing and documentation changes. |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2014年10月01日 22:56:07 | paul.j3 | set | recipients:
+ paul.j3, bethard, docs@python |
| 2014年10月01日 22:56:07 | paul.j3 | set | messageid: <1412204167.18.0.738196184941.issue22401@psf.upfronthosting.co.za> |
| 2014年10月01日 22:56:07 | paul.j3 | link | issue22401 messages |
| 2014年10月01日 22:56:06 | paul.j3 | create |
|