Make shell argument parsers from type hints
Project description
infer-parser
infer-parser is a Python library for making shell argument parsers from type hints.
Install
pip install infer-parser
Example
import typing as t
from infer_parser import make_parser
parse = make_parser(t.Optional[int])
assert parse(["5"]) == 5
assert parse(["-11"]) == -11
assert parse([""]) is None
assert parse(["None"]) is None
try:
parse(["12.13"])
except ValueError:
print("not an Optional[int]")
parse_tuple = make_parser(tuple[float, ...])
assert parse_tuple(["1.5"]) == (1.5,)
assert parse_tuple(["0.0", "4.2", "-1"]) == (0.0, 4.2, -1.0)
assert parse_tuple([]) == ()
try:
parse(["Hello, world!"])
except ValueError:
print("not a tuple[float, ...]")
Limitations
infer-parser cannot always infer a parser.
import typing as t
from infer_parser import make_parser
try:
make_parser(t.Callable[..., int])
except TypeError:
print("not supported")
License
MIT.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
infer_parser-0.1.1.tar.gz
(7.3 kB
view hashes)
Built Distribution
Close
Hashes for infer_parser-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20377cdf9f36ebe940d98c4d4e2b72be4baa2161b1e9f58e9358e7e606cbae37 |
|
MD5 | 911027333f4e838a79d2bcf6a22811a9 |
|
BLAKE2b-256 | a67e8255066572096c6f4ad861a4d94bcc0a5dccc0a91e8249e9e868c4b4bc65 |