Skip to main content

A simple decorator to control the type matching of the arguments passed

Project description

Check Type Wrapper

This is a simple function decorator that takes data types as parameters. These types must match the types of the arguments to the function. In case of type mismatch, an exception is thrown informing about the mismatch of the expected type with the received function

Installation

Сreate a virtual environment in the project folder using the venv tool

$ python3 -m venv env

Activate the virtual environment

$ . env/bin/activate

Using PIP, install the third party decorator package

$ pip install Quastrado_check_type_wrapper

Usage

Import the decorator. Write a simple function and wrap

from check_type_wrapper import check_type

@check_type(int, int)
def func(arg1, arg2):
    return a + b

result = func('1', '2')

By passing parameters to the decorator, we indicate that the arguments that the function will accept must be of a numeric type. But, when calling the function, we will pass it two strings

Having run the code, in the terminal we should see the following in the terminal

...
    raise TypeMissMatchException(discrepancies)
check_type_wrapper.exception.TypeMissMatchException: 
Invalid type of argument 1. Expect int, not str
Invalid type of argument 2. Expect int, not str

Status

Still in development

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

File details

Details for the file Quastrado_check_type_wrapper-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: Quastrado_check_type_wrapper-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.6.9

File hashes

Hashes for Quastrado_check_type_wrapper-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 22794cf9f0186726f0d8203e13d10924743647f86f00e473c5c02edb4615bc02
MD5 bcf5047ded6589bb97106d2e43ed1671
BLAKE2b-256 4210510a639d73b98da40e2b70e277390d2e0b10a90f6419987c72a7140cc5cd

See more details on using hashes here.

Supported by

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