Skip to content
/ cwtch Public

Python Data Classes with validation and views

License

Notifications You must be signed in to change notification settings

levsh/cwtch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cwtch [wip] - Python Data Classes with validation.

tests coverage License: MIT

In [1]: from cwtch import dataclass, field

In [2]: @dataclass
   ...: class D:
   ...:     i: int
   ...:     s: str = field(validate=False)
   ...:

In [3]: D(i=1, s='s')
Out[3]: D(i=1, s='s')

In [4]: D(i='i', s='s')
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
File /vagrant/dev/cwtch/ext/core.pyx:618, in cwtch.core.make.validate_value_using_validator()
...

ValueError: invalid literal for int() with base 10: 'i'

During handling of the above exception, another exception occurred:

ValidationError                           Traceback (most recent call last)
...

ValidationError: type=[<class 'int'>] input_type=[<class 'str'>]
  E: invalid literal for int() with base 10: 'i'

During handling of the above exception, another exception occurred:

ValidationError                           Traceback (most recent call last)
Cell In[4], line 1
----> 1 D(i='i', s='s')

File <string>:11, in __init__(__cwtch_self__, i, s, **__cwtch_kwds__)

ValidationError: type=[<class '__main__.D'>] path=['i'] input_type=[<class 'str'>]
  type=[<class 'int'>] input_type=[<class 'str'>]
    E: invalid literal for int() with base 10: 'i'

In [5]: D(i='1', s=0)
Out[5]: D(i=1, s=0)

About

Python Data Classes with validation and views

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published