view.py icon indicating copy to clipboard operation
view.py copied to clipboard

Supporting TypeVar's in type validation

Open ZeroIntensity opened this issue 1 year ago • 0 comments

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

ZeroIntensity avatar Feb 09 '24 15:02 ZeroIntensity