ZeroIntensity / view.py

The Batteries-Detachable Web Framework
https://view.zintensity.dev
MIT License
206 stars 15 forks source link

Adding a public interface for validating type codes #116

Closed ZeroIntensity closed 5 months ago

ZeroIntensity commented 6 months ago

Feature description

The type code system used in _view for handling type validation works quite well, but there's no good API for accessing it from Python. The user should be able to do manual type validation if they feel like it.

Feature example API

from view import compile_type
from typing import TypedDict

class Test(TypedDict):
    a: str

tp = compile_type(Test)
tp.validate({"a": "b"})  # OK
tp.check_type({})  # False

Anything else?

This will delay #30, again.