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(LightType[str]):
@classmethod
def validate(cls, value: str) -> bool:
return value.startswith("String")
With Pydantic
from light_types import LightType
class StartsWithString(LightType[str]):
@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-0.0.1.tar.gz
(6.2 kB
view hashes)
Built Distribution
Close
Hashes for light_types-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 349900469d37c51ff9dd18ace395ef5bc2f5441e5f93cfee43014b2506431a69 |
|
MD5 | e34de38f86bfdfa754605231264d1b0f |
|
BLAKE2b-256 | 533d82f5ec43826cd12d68a8f299499271375f4570b517300eebbd2b209fb257 |