Skip to main content

No project description provided

Project description

How to Import

from type_checker.decorators import enforce_strict_types

Examples utilisation

from dataclasses import dataclass

from type_checker.decorators import enforce_strict_types


@enforce_strict_types
@dataclass
class Person:
    name: str
    age: int


def test_greet_person_with_wrong_types():
    try:
        Person(123, "twenty")
    except TypeError as e:
        assert (
            str(e)
            == "Problem on function Person, Expected type '<class 'str'>' for argument 'name' but received type '<class 'int'>' instead"
        )
    try:
        Person("Alice", "twenty")
    except TypeError as e:
        assert (
            str(e)
            == "Problem on function Person, Expected type '<class 'int'>' for argument 'age' but received type '<class 'str'>' instead"
        )

from type_checker.decorators import enforce_strict_types


@enforce_strict_types
def greet(name: str, age: int):
    print(f"Hello, {name}! You are {age} years old.")


def test_greet_with_wrong_types():
    try:
        greet(123, "twenty")
    except TypeError as e:
        print(str(e))
        assert (
            str(e)
            == "Problem on function greet, Expected type '<class 'str'>' for argument 'name' but received type '<class 'int'>' instead"
        )
    try:
        greet("Alice", "twenty")
    except TypeError as e:
        assert (
            str(e)
            == "Problem on function greet, Expected type '<class 'int'>' for argument 'age' but received type '<class 'str'>' instead"
        )

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

type_checker_decorators-0.1.2.tar.gz (2.2 kB view details)

Uploaded Source

Built Distribution

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

type_checker_decorators-0.1.2-py3-none-any.whl (2.2 kB view details)

Uploaded Python 3

File details

Details for the file type_checker_decorators-0.1.2.tar.gz.

File metadata

  • Download URL: type_checker_decorators-0.1.2.tar.gz
  • Upload date:
  • Size: 2.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.9.2 Linux/5.10.0-21-amd64

File hashes

Hashes for type_checker_decorators-0.1.2.tar.gz
Algorithm Hash digest
SHA256 45aab95174c7f75b963809dac70da862956e7392dab0e523d639bd106c4c7823
MD5 49d47ff2e696222888b7d6de770c9000
BLAKE2b-256 4a7b19d731bf723abac65aa3f6bad23a159a2a44dae4b1f4ba2ad82f11fe3988

See more details on using hashes here.

File details

Details for the file type_checker_decorators-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for type_checker_decorators-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ec39ee3d0386c8a277b66b85329978cff7246f20f3359b029d56fc50682ebcff
MD5 b125f4d7232011ca84825e1aafb2f315
BLAKE2b-256 8785f3c01d7278e12a6e00b556e0627e9d582020bde5de361e0a5d08d35cf825

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