Added support for `action=`
In [`argparse`](https://docs.python.org/3/library/argparse.html), it is possible to specify actions that modify how the parsed arguments are used. For example, `action='append'` appends the provided arguments to an existing list. Actions are specified as parameters in calls to the `self.add_argument` function within the user's override of the `add_arguments` method. A complete example is as follows:
python
from tap import Tap
from typing import List
class Args(Tap):
arg: List[int] = [1, 2]
def add_arguments(self):
self.add_argument('--arg', action='append')
args = Args().parse_args('--arg 3 --arg 4'.split())
print(args.arg) [1, 2, 3, 4]
We added support for all actions defined by `argparse`: count, const, append_const, append, extend, store_true, store_false, store_const, and version. However, we don't guarantee consistent behavior with `argparse` for custom actions.
Improved Argument Saving
The `as_dict` method has been modified to return not just parsed arguments but also properties and other attributes set by the user. Since `save` uses `as_dict` internally, the same modification applies to `save`. Thus, the new `as_dict` and `save` will return a superset of the attributes it returned previously. For example:
python
from tap import Tap
class Args(Tap):
arg: int = 2
def __init__(self):
super(Args, self).__init__()
self._prop = 'hi'
property
def prop(self):
return self._prop
args = Args().parse_args()
print(args.as_dict()) previous version: {'arg': 2}, new version: {'arg': 2, 'prop': 'hi'}
Fixes
1. Fixed an issue to ensure that `dest=` works properly and `as_dict` correctly dumps all parameters
2. Fixed reliance on source code parsing to enable editing of Tap code without affecting currently running programs
3. Fixed an issue to prevent class methods from being included as parsed class variables