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.

Metadata

Release files for simple-type-checker 2.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for simple-type-checker 2.3.1
File Size Uploaded Provenance Actions
simple_type_checker-2.3.1.tar.gz 19.2 kB Without provenance Details for simple_type_checker-2.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for simple-type-checker 2.3.1
File Interpreter ABI Platform Actions
simple_type_checker-2.3.1-py3-none-any.whl Python 3 none any Details for simple_type_checker-2.3.1-py3-none-any.whl

Total release size: 39.6 kB

Release files / simple_type_checker-2.3.1.tar.gz

Download URL simple_type_checker-2.3.1.tar.gz
Size 19.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d0ca11de049962a6de27ce4dfd113290d9426734bf70578b809b551fc07676df
BLAKE2b-256 checksum
How to use checksums
c5bd93ce8ecf24a41377de554ceac121deb5083cc3f840f092008a19581ff570
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / simple_type_checker-2.3.1-py3-none-any.whl

Download URL simple_type_checker-2.3.1-py3-none-any.whl
Size 20.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cf8e8004e9b48fee54dbd3b81b304da5fe4a4be704e2615e542c5296eaf0ce81
BLAKE2b-256 checksum
How to use checksums
d8dc3334a1fb11052cd0769fc7ac92a58a297a6cc06c62e9bd6d914704124e1f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for simple-type-checker 2.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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