Typed-argument-parser

Latest version: v1.10.0

Safety actively analyzes 629723 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 3 of 4

1.5.4

Changed saving and loading to better handle unpicklable attributes

Save now has the `skip_unpicklable` flag that when set to `True` skips unpicklable attributes and when loaded produces an `UnpicklableObject` placeholder for that attribute, indicating that the attribute must be set specially. The signature of save is now:
python
save(self, path: str, with_reproducibility: bool = True, skip_unpicklable: bool = False) -> None

1.5.3

Support for Native Multiline Help Strings

Previously, `Tap` made it possible to specify the help string for an argument using a single line comment. Now, `Tap` also supports specifying the help string with a multiline comment below the class variable for the argument. If both a single line comment and a multiline comment are provided, the two are concatenated with a space.

python
main.py
from tap import Tap


class Args(Tap):
arg: bool = False This is the one-line summary.
"""
This is the multiline explanation.
"""


args = Args().parse_args()




usage: main.py [--arg1] [-h]

optional arguments:
--arg (bool, default=False) This is the one-line summary. This
is the multiline explanation.
-h, --help show this help message and exit

1.5.2

`as_dict` bug fix

The Tap method `as_dict` failed to include certain attributes, such as properties, when they exist in a super class Tap and not in the sub class Tap. For example, consider the following:

python
from tap import Tap


class SuperPropertyTap(Tap):
a: str

property
def pi(self):
return 3.14


class SubPropertyTap(SuperPropertyTap):
b: int = 1


super_args = SuperPropertyTap().parse_args()
print(super_args.as_dict()) includes pi=3.14

sub_args = SubPropertyTap().parse_args()
print(sub_args.as_dict()) does NOT include pi=3.14 but should


In this example, the super class Tap does include the property `pi` in its `as_dict` but the sub class Tap does not. This has now been fixed so that both include the property `pi` in their `as_dict`.

1.5.1

1.5.0

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

1.4.3

Previously, `has_git` only checked whether git was installed on the system. Now, it also checks whether the current working directory is inside a git repo to prevent errors where the code is not inside a git repo.

Page 3 of 4

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.