ZeroIntensity / view.py

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

Supporting TypeVar's in type validation #154

Open ZeroIntensity opened 4 months ago

ZeroIntensity commented 4 months ago

Improvement Description

Along with #153, View does not support TypeVar being used in the type validation API. This isn't nearly as important as Literal, but should still be implemented.

Improvement Request Example API

from view import compile_type
from typing import TypeVar, Generic
from dataclasses import dataclass

T = TypeVar("T")

@dataclass
class Thing(Generic[T]):
    hello: T
    world: T

tp = compile_type(Thing)
tp.cast('{"hello": "world", "world": "hello"}')  # creates Thing instance
tp.is_compatible('{"hello": "world", "world": 1}')  # T is not the same across the object, returns False

Anything else?

No response