Skip to main content

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:

  • True if the value matches the expected type, otherwise False.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytypevalidator-0.1.0.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytypevalidator-0.1.0-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

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

Hashes for pytypevalidator-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8e43c2613c99b035e15637917e464d254dfe4c8a92eba19949597002728d3008
MD5 3698f0141192651bd02900e21f60a94b
BLAKE2b-256 f70401400c805a76414246c9962183164734049802672fcc376eca2d02bd0404

See more details on using hashes here.

File details

Details for the file pytypevalidator-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytypevalidator-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e81d433279cd7ef07f90ecde9db6280595484d2835a9657e7746130d27f9f5a6
MD5 3e049f83108d04c42349cd7d913e8d31
BLAKE2b-256 7122bbfc168addc67617bb9f1729d8a9c4e47af58df2a44357cf4455693c559e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page