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.3.tar.gz (1.8 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.3-py3-none-any.whl (2.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: type_checker_decorators-0.1.3.tar.gz
  • Upload date:
  • Size: 1.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.9.16 Linux/6.1.0-11-amd64

File hashes

Hashes for type_checker_decorators-0.1.3.tar.gz
Algorithm Hash digest
SHA256 0bf7e65a699e7147d65d1c8476989588970fda2352edc60b9270c10b74dbcb36
MD5 e8e0fabe3d55672215bc3fbffb2f03d1
BLAKE2b-256 1c60609dd0e313f986dfad0d90c1b339ed4a6d784add4f57a87ebf0bc569faa1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for type_checker_decorators-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b5b877522cbdcfaeaea1042ed301bc55068233dac80f9762e887eff2a969e213
MD5 995ada56797a9025415417671bd2f450
BLAKE2b-256 5bdf4a3c4b368d2de7e62d01225f4fb457d4b7a17b1d9a58dd2005b996f0eafa

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