Validation utilities
Project description
easyvalidate
A Python package containing utilities for different types of validations:
- Validation of types
- Validation of values based on various conditions
- Validation of method protection
Installation
You can install the package from PyPI using pip:
$ pip install easyvalidate
Feature Highlights
Typehint Validation
The package contains a decorator: validate_types()
. Add it to any
function you want to validate types for, but make sure you have type hints
on your function:
import typing
from easyvalidate import validate_typehints
@validate_typehints()
def foo(x: int, y: typing.Union[int, str]):
print(x, y)
foo(5, 10) # works
foo(5, 'hello!') # also works
foo(5, []) # error!
The decorator comes with a few arguments:
all: bool = True
: whether to require that all arguments (exceptself
) are type-hinted. It's enabled by default.deep: bool = False
: whether to recursively validate all members of collections passed to the function. This can be painfully slow on large datasets so it's disabled by default.
Caller Validation
Sometimes we really don't want people calling internal methods (i.e. those that start with an underscore by convention)
from outside the enclosing class. Here we can use the @private
or @protected
decorators:
from easyvalidate import private, protected
class Foo:
@protected
def _my_protected_meth(self):
pass
@private
def _my_private_meth(self):
pass
def my_public_meth(self):
self._my_protected_meth() # works as expected
self._my_private_meth() # works as expected
class Bar(Foo):
def my_public_meth(self):
self._my_protected_meth() # works as expected
self._my_private_func() # error!
The @private
and @public
decorators are a bit limited as of now:
- They only work for CPython for now.
- They don't prevent overriding the methods in subclasses.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
easyvalidate-0.0.1.tar.gz
(15.4 kB
view hashes)
Built Distribution
Close
Hashes for easyvalidate-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4894fd8f7836063b89377ec60430f202fb34c1190a0e6cf7fe69847bf3dfd881 |
|
MD5 | cd35b4b042a63c8896afab163e809c08 |
|
BLAKE2b-256 | b53e6d163a8b640d947c55ffb74ed43f3c3783102f22a07afaed583dc7566c76 |