Skip to main content

Introduce strict typing in your functions.

Project description

Introspector

[WIP] A Python library to write strongly typed code.

Table of contents

Introduction

Introduce strict typing in your functions.
This project is under development.

Requirements

  • Python >= 3.10

Basic usage

import introspector

@introspector.strict
def foo(a: int, b: list[dict[str, Any]]) -> list[int]:
    # Some funny code...

    return [1, 2, 3, 4]

foo(
    42, 
    [
        {
            'x': ['hello', 'world'],
            'y': 3.14,
        },
    ],
)

When the code is executed, the instrospector.strict decorator will inspect the signature of the foo function and compare it with the values passed in its parameters.
If the typing of the values does not match the signature of the function, introspector will throw a TypeError exception.

Python 3.10 supported typing syntax

This paclage support the following typing syntaxes:

Name Description Example
| operator The Union type shortcut syntax int | float

Instrospector.strict available options

:arrow_right: ignore

A list of parameter names that will be excluded from the typing control.
Notice that the ignore option will always contains self and cls.

Example:

@instrospector.strict(ignore=['b'])
def foo(a: int, b: float) -> None:
    ...

The argument b will be ignored by the typing control.

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

introspector-0.2.1a0.tar.gz (5.6 kB view hashes)

Uploaded Source

Built Distribution

introspector-0.2.1a0-py3-none-any.whl (6.2 kB view hashes)

Uploaded Python 3

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