Install & Compatibility
Where this runs
tested against v0.12.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.006s · 17.8MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.5s · import 0.006s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Integer
✓ from argparse_addons import Integer
This quickstart demonstrates how to define an argument using the `Integer` type from `argparse-addons`, enforcing a value within a specified range. It uses a standard `argparse.ArgumentParser` instance.
import argparse
from argparse_addons import Integer
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument(
'--value',
type=Integer(0, 255),
help='An integer value between 0 and 255.'
)
args = parser.parse_args(['--value', '128'])
print(f'Parsed value: {args.value}')
# Example of invalid input (will raise an error during parse_args)
# try:
# parser.parse_args(['--value', '-1'])
# except SystemExit as e:
# print(f'Error: {e}')
Debug
Known issues
gotchaCalling `parser.parse_args()` at the top level of an imported module can lead to unexpected argument parsing behavior or errors in the main script. Always guard `ArgumentParser` instantiation and `parse_args()` calls within an `if __name__ == "__main__":` block if the module is intended to be imported.fixWrap `ArgumentParser` creation and `parse_args()` calls in `if __name__ == "__main__":`.
affects: All versions of argparse-addons (inherent argparse behavior)
gotchaWhen a positional argument is defined with `nargs='*'` (zero or more arguments) and also `choices`, providing no values for that argument can result in an 'invalid choice: []' error, because `argparse` attempts to validate an empty list against the defined choices.fixConsider if `nargs='*'` is truly appropriate with `choices` for positional arguments, or explicitly add `[]` to your `choices` (though this might clutter help output). Alternatively, ensure a default is set that is within `choices`.
affects: All versions of argparse-addons (inherent argparse behavior)
gotchaThe interaction between `default` values and actions like `action='append'` or `action='extend'` can be non-intuitive. Default values might be prepended to user-provided input, making it difficult to completely override the default without custom logic.fixAvoid using `default` directly with `action='append'` or `action='extend'` if the intention is for the user's input to completely replace the default. Instead, handle default list population manually after `parse_args()`.
affects: All versions of argparse-addons (inherent argparse behavior)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'argparse_addons'
The 'argparse_addons' module is not installed or is installed incorrectly.
fixInstall the module using pip: 'pip install argparse-addons'.
TypeError: '>' not supported between instances of 'str' and 'int'
Comparing a string argument to an integer without converting the string to an integer first.
fixConvert the argument to an integer before comparison: 'if int(args.detect_mode) > 1:'.
argparse.ArgumentError: argument --foo: conflicting option string: --foo
Defining two arguments with the same option string in argparse.
fixEnsure each argument has a unique option string in the ArgumentParser definition.
argparse.ArgumentTypeError: invalid int value: 'net_model'
Providing a non-integer value for an argument expected to be an integer.
fixEnsure that the value provided for the argument is a valid integer.
SyntaxError: invalid syntax
Using f-string syntax in a Python version that does not support it.
fixUpgrade to Python 3.6 or later, or use an alternative string formatting method.
Upgrade
Version history
0.12.0latest on PyPI · released Jan 29, 2023
Audit
Dependencies
No dependency data recorded yet.