Skip to main content

Library for generating shell parsers from type hints

Project description

infer-parser

infer-parser is a Python library for inferring shell parsers from type hints.

Example

from typing import Optional
from infer_parser import infer, CantParse

parse = infer(Optional[int])

assert parse("5") == 5
assert parse("-11") == -11
assert parse("") is None
assert parse("None") is None
assert isinstance(parse("12.13"), CantParse)

parse_tuple = infer(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("") == ()
assert isinstance(parse_tuple("Hello, world!"), CantParse)

Limitations

infer-parser cannot always infer a parser.

from typing import Callable
from infer_parser import infer, CantInfer

parse = infer(Callable[..., int])  # not supported
assert isinstance(parse, CantInfer)

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.0.1.tar.gz (5.1 kB view hashes)

Uploaded Source

Built Distribution

infer_parser-0.0.1-py3-none-any.whl (6.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page