Skip to main content

lilVali

A small Python 3.12 validation experiment for playing with PEP 695.

Supports most basic typing constructs including Generics. Also supports dataclasses and classes with annotated __init__ methods.

Install

pip install lilvali

Usage

from lilvali import validate, validator
from lilvali.errors import *

Simple examples

@validate
def add[T: (int, float)](x: int, y: T) -> int | float:
    return x + y


def main():
    print(f"{add(1, 2)=}")
    print(f"{add(1, 2.0)=}")

    try:
        print(f"{add(1.0, 2)=}")
    except ValidationError as e:
        print(f"{e=}")
    else:
        raise RuntimeError("Expected ValidationError")


if __name__ == "__main__":
    main()
@validate
@dataclass
class SomeClass:
    x: int
    y: str = field(default="hello")

    @validator
    def _x(value):
        if value is None or value < 0:
            raise ValidationError

    @validator
    def _y(value) -> bool:
        return value == "hello"


@validate
class NotADC:
    def __init__(self, x: int, y: str):
        self.x = x
        self.y = y

    @validator
    def _x(value):
        if value is None or value < 0:
            raise ValidationError

    @validator
    def _y(value) -> bool:
        return value == "hello"

See the demo folder as well.

Tests

$ ./test.sh
Running tests with coverage
.........................
----------------------------------------------------------------------
Ran 25 tests in 0.006s

OK
Name                           Stmts   Miss  Cover   Missing
------------------------------------------------------------
lilvali/__init__.py                2      0   100%
lilvali/binding.py               167      0   100%
lilvali/errors.py                  6      0   100%
lilvali/validate.py               80      0   100%
tests/test_tiny_validate.py      195      0   100%
tests/test_validate_types.py     124      0   100%
------------------------------------------------------------
TOTAL                            574      0   100%

TODO

Release files for lilvali 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lilvali 0.1.6
File Size Uploaded
lilvali-0.1.6.tar.gz 13.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lilvali 0.1.6
File Interpreter ABI Platform
lilvali-0.1.6-py3-none-any.whl Python 3 none any Details

Total release size: 31.6 kB

Release files / lilvali-0.1.6.tar.gz

Download URL lilvali-0.1.6.tar.gz
Size 13.6 kB
Tags Source
SHA-256 checksum
How to use checksums
bdc337ae10699be73ede4ebd8ef07e46845f926ecb3146e55c437a1336496ce5
BLAKE2b-256 checksum
How to use checksums
032f7377bf1a0723c0ba63f4feebc42f825c3bed3540b841af29d63f2275ca58
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Release files / lilvali-0.1.6-py3-none-any.whl

Download URL lilvali-0.1.6-py3-none-any.whl
Size 18.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
499b4727e7ef7622efb12a1991f6d1963627073ef05de559340e7e127b653222
BLAKE2b-256 checksum
How to use checksums
0a71829f4494ad03f97062a4b41939bc28a2435076baede075262f991d62147a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Release history Release notifications | RSS feed

This release

0.1.6 This release

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page