Parse, don't validate
Project description
Light Types
"Parse, don't validate"
Compatible with PydanticV2
Inspired by Phantom types
Examples
Sample
from light_types import LightType
class StartsWithString(str, LightType):
@classmethod
def validate(cls, value: str) -> bool:
return value.startswith("String")
With Pydantic
from light_types import LightType
class StartsWithString(str, LightType):
@classmethod
def validate(cls, value: str) -> bool:
return value.startswith("String")
class MyModel(BaseModel):
value: StartsWithString
assert TypeAdapter(MyModel).validate_python({"value": "StringOk"})
Tests, linting, formatting
rye test | lint | fmt
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
light_types-1.0.1.tar.gz
(6.5 kB
view hashes)
Built Distribution
Close
Hashes for light_types-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 778c2f2ca488e3ea637f25488b33bf2b1bf9bc6bb872805ddf44bbb30c950dfa |
|
MD5 | 21b5d7acc1f8ba281180cb02b759a9cb |
|
BLAKE2b-256 | 5f3c406ee0da1dcb5621a0d34eecc13ed23e700c6b3e893b8307854f5435e2ad |