Skip to main content

simple_type_checker

A small extendable python type checker library

Basic Usage

Checking a type:

from simple_type_check import type_check
assert type_check("A string", str)

As a decorator:

from simple_type_check import type_check, TypeCheckFailed

@type_check.returns
def id_(x) -> int:
    return x

_ = id_(1)  # Passes
try:
    _ = id_("string")  # Raises
except TypeCheckFailed as e:
    pass

Decorators for aruments exist as well: type_check.args. Both can be done at once with type_check.decorate.

With custom types

Basic types where isinstance is sufficient:

from simple_type_check import TypeChecker

class Foo:
    pass

type_check = TypeChecker(Foo)

assert type_check(Foo(), Foo)

Special type checking logic desired:

from simple_type_check import TopLevelCheck, TypeChecker

Bar = list[int] | list["Bar"]

class BarCheck(TopLevelCheck):
    def __call__(self, obj, type_) -> bool:
        return type_ == "Bar" and self._recurse(obj, Bar)

type_check = TypeChecker(advanced=[BarCheck])

type_check([1, [2], [[3]]], Bar)  # Should pass

This use case is useful for container types that take arguments, for example.

Download files

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

Source Distribution

simple_type_checker-2.2.1.tar.gz (19.2 kB view details)

Uploaded Source

Built Distribution

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

simple_type_checker-2.2.1-py3-none-any.whl (20.4 kB view details)

Uploaded Python 3

File details

Details for the file simple_type_checker-2.2.1.tar.gz.

File metadata

  • Download URL: simple_type_checker-2.2.1.tar.gz
  • Upload date:
  • Size: 19.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for simple_type_checker-2.2.1.tar.gz
Algorithm Hash digest
SHA256 cceed17666a18fe6cd728ba7b7bdfd802bb3700c1e884815de3e29cb8a72abda
MD5 f2c9d09c509a577dd97dc5a7a818e975
BLAKE2b-256 b8201a0c97ff1a7829a0556ffd6bebfc41e59ff99122f225a6516c76faa7d160

See more details on using hashes here.

File details

Details for the file simple_type_checker-2.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for simple_type_checker-2.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dc41f235f57eff272a539d88ec46904abfaaaf5c8b553660079fb2a3c77e6690
MD5 7fd386f046c3b46d65bccdf8ceaa8a21
BLAKE2b-256 d5a1311ede011c5b4dcda969983baec41945f0e91a9a2ba29264f2630050db0b

See more details on using hashes here.

Release history Release notifications | RSS feed

2.3.1

2 files

2.3.0

2 files

This release

2.2.1 This release

2 files

2.2.0

2 files

2.1.2

2 files

2.1.1

2 files

2.1.0

2 files

2.0.0

2 files

1.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page