Typed-argument-parser

Latest version: v1.10.0

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

Scan your dependencies

Page 2 of 4

1.7.1

Changing reproducibility info git path

Previously, the reproducibility information came from the git repo in the current working directory. Now, by default, the reproducibility information comes from the git repo of the directory containing the file that is run, regardless of the current working directory. Specify a particular git repo by setting the `repo_path` parameter in the `save` method.

1.7.0

Support for `list`, `set`, and `tuple`
If you're using Python 3.9+, then you can type arguments with `list`, `set`, and `tuple` as well as their boxed variants (e.g., `list[int]`).

Bug fixes and minor improvements
https://github.com/swansonk14/typed-argument-parser/commit/8e29d9d2e534239ad0eec4cacfd95bc1449c81a9 Made the saved reproducibility information work for arguments with spaces such as `--arg "Multiple words"` .
https://github.com/swansonk14/typed-argument-parser/commit/5b2eab67473a90e05d1ed5d2397914a5f33d1f9e Added support for pickling `Tap` objects.
https://github.com/swansonk14/typed-argument-parser/pull/54 Fixed an issue where Tap overwrote actions (thanks to Cebtenzzre).
https://github.com/swansonk14/typed-argument-parser/commit/f30ffbe46aa08a68aa84f8edd6062fa9e69eea68 Prevent changing underscores to dashes in positional arguments.
https://github.com/swansonk14/typed-argument-parser/issues/48 `underscores_to_dashes` now works for default/required values (thanks to marcoffee).

1.6.3

The latest version of `typing-inspect`, version 0.7.0, has a [bug](https://github.com/ilevkivskyi/typing_inspect/issues/73) which causes Tap to break. This release forces installation of `typing-inspect` version 0.6.0, which is compatible with Tap. This release also includes several minor fixes.

1.6.2

Complex Types

Tap now supports types boxed in an `Optional` such as `Optional[Tuple[bool, str, int]]`.

Tap also supports arbitrary objects with one parameter in their constructor. For example:

python
from tap import Tap
from pathlib import Path

class Args(Tap):
arg: Path

args = Args().parse_args(['--arg', 'file.txt'])
print(args.arg, type(args.arg)) file.txt <class 'pathlib.PosixPath'>


Improved Testing Infrastructure

Tap has now transitioned from Travis CI to GitHub Actions for running tests. Additionally, tests are now run on Windows and MacOS in addition to Linux. Code coverage is also determined and is displayed on the README.

1.6.1

Configuration files may now be loaded along with arguments with the optional flag `config_files: List[str]`. This addresses https://github.com/swansonk14/typed-argument-parser/issues/25, thanks to arbellea.

For example, if you have the config file `my_config.txt`

--arg1 1
--arg2 two

then you can write
python
from tap import Tap

class Args(Tap):
arg1: int
arg2: str

args = Args(config_files=['my_config']).parse_args()


Arguments passed in from the command line overwrite arguments from the configuration files. Arguments in configuration files that appear later in the list overwrite the arguments in previous configuration files.

1.6.0

Subparsers

Tap now supports [subparsers](https://docs.python.org/3.8/library/argparse.html#argparse.ArgumentParser.add_subparsers).

To add a subparser, override the `configure` method and call `self.add_subparser`. Optionally, to specify keyword arguments (e.g., `help`) to the subparser collection, call `self.add_subparsers`. For example,

python
class SubparserA(Tap):
bar: int bar help

class SubparserB(Tap):
baz: Literal['X', 'Y', 'Z'] baz help

class Args(Tap):
foo: bool = False foo help

def configure(self):
self.add_subparsers(help='sub-command help')
self.add_subparser('a', SubparserA, help='a help')
self.add_subparser('b', SubparserB, help='b help')


Configure

Tap has a new method called `configure` which is called at the end of initialization. Two uses of `configure` are `add_argument` (previously called in `add_arguments`, which has now been deprecated) and `add_subparser`. For example,

python
class SubparserA(Tap):
bar: int

class Args(Tap):
foo: bool = False

def configure(self):
self.add_argument('--foo', '-f')
self.add_subparser('a', SubparserA)

Page 2 of 4

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.