A simple utility class to validate and convert types in Python
Project description
TypeValidator Class
Overview
The TypeValidator class is a simple utility designed to validate the types of variables in Python. It provides methods to validate the type of a single value as well as multiple values against their expected types. This can be especially useful for ensuring data integrity and correctness in your code when dealing with dynamic data or user inputs.
Features
- Single value validation: Validate if a single value matches the expected type.
- Multiple value validation: Validate a list of values against a list of expected types.
- Error handling: Raises an exception if the number of values does not match the number of expected types in batch validation.
Methods
validate(self, value, expected_type)
This method validates whether a single value matches the expected type.
Parameters:
value: The value to check.expected_type: The type that the value is expected to be.
Returns:
Trueif the value matches the expected type, otherwiseFalse.
Example Usage:
// Validate a single Variabale
type_validator = TypeValidator()
result = type_validator.validate(42, int)
print(result) # Output: True
// Check multiple values
id = 0
email = 1
isActiveAccount = False
Amount = 12.78
values = [id, email,isActiveAccount, Amount]
expected_types = [int, str,bool, float]
print(validator.validate_all(values, expected_types))# [True,False, True, True]
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytypevalidator-0.1.0.tar.gz.
File metadata
- Download URL: pytypevalidator-0.1.0.tar.gz
- Upload date:
- Size: 13.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e43c2613c99b035e15637917e464d254dfe4c8a92eba19949597002728d3008
|
|
| MD5 |
3698f0141192651bd02900e21f60a94b
|
|
| BLAKE2b-256 |
f70401400c805a76414246c9962183164734049802672fcc376eca2d02bd0404
|
File details
Details for the file pytypevalidator-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pytypevalidator-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e81d433279cd7ef07f90ecde9db6280595484d2835a9657e7746130d27f9f5a6
|
|
| MD5 |
3e049f83108d04c42349cd7d913e8d31
|
|
| BLAKE2b-256 |
7122bbfc168addc67617bb9f1729d8a9c4e47af58df2a44357cf4455693c559e
|