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-1.0.0.tar.gz
(6.4 kB
view hashes)
Built Distribution
Close
Hashes for light_types-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b16c21a7b9482166b7a8355a30fcabbb0d94411c0df1c5033fa3f6a50990968 |
|
MD5 | 6eae6ad7862070027464feb3afa22829 |
|
BLAKE2b-256 | e71703a53237e95a7873bc23a5800051d7a7fed2ad4000a0137ec6e33a5606fb |