Runtime Type Checking in Python 3

Related tags

Miscellaneous typo
Overview

typo

This package intends to provide run-time type checking for functions annotated with argument type hints (standard library typing module in Python 3.5, or backports.typing package in Python 3.3 / 3.4).

Example:

from typing import Sequence, List
from typo import type_check

@type_check
def f(x: int, s: Sequence[int]) -> List[int]:
	...

The @type_check decorator ensures that the values passed to annotated arguments will have their types checked before the function is executed; return value can be optionally checked as well.

If the value types are not consistent with the function signature, a TypeError with a descriptive error message will be raised. For instance, calling function f from the example above with wrong argument types,

>>> f(1, (0, 2.2))

results in an exception being thrown:

TypeError: invalid item #1 of `s`: expected int, got float

Note: this is work-in-progress and not all typing primitives are supported; however all supported constructs should be covered by a good number of tests.

Here's some of the supported type hints: simple types, List, Dict, Tuple, Sequence, Set, TypeVar (with support for constraints and upper bounds).

What's not supported: Iterator and Generator (which we can't inspect due to their laziness), Callable (which we can't check without calling it), forward references (which is possible to support but requires more work), covariant and contravariant type variables (this requires more thought but isn't likely to be helpful in the runtime context).

You might also like...
Async-first dependency injection library based on python type hints

Dependency Depression Async-first dependency injection library based on python type hints Quickstart First let's create a class we would be injecting:

Force you (or your user) annotate Python function type hints.

Must-typing Force you (or your user) annotate function type hints. Notice: It's more like a joke, use it carefully. If you call must_typing in your mo

A type based dependency injection framework for Python 3.9+

Alluka A type based dependency injection framework for Python 3.9+. Installation You can install Alluka from PyPI using the following command in any P

Type Persian without confusing words for yourself and others, in Adobe Connect
Type Persian without confusing words for yourself and others, in Adobe Connect

About In the Adobe Connect chat section, to type in Persian or Arabic, the written words will be confused and will be written and sent illegibly (This

Handwrite - Type in your Handwriting!
Handwrite - Type in your Handwriting!

Handwrite - Type in your Handwriting! Ever had those long-winded assignments, that the teacher always wants handwritten?

Pre-commit hook for upgrading type hints

This is a pre-commit hook configured to automatically upgrade your type hints to the new native types implemented in PEP 585.

Sudo type me a payload

payloadSecretary Sudo type me a payload Have you ever found yourself having to perform a test, and a client has provided you with a VM inside a VDI in

Tracking development of the Class Schedule Siri Shortcut, an iOS program that checks the type of school day and tells you class scheduling.

Class Schedule Shortcut Tracking development of the Class Schedule Siri Shortcut, an iOS program that checks the type of school day and tells you clas

Owner
Ivan Smirnov
Musician. Coder. Quant.
Ivan Smirnov
This is a simple python script for checking A/L Examination results of srilankan students

AL-Result-Checker This is a simple python script for checking A/L Examination results of srilankan students INSTALLATION [Termux] [Linux] : apt-get up

Razor Kenway 8 Oct 24, 2022
Runtime fault injection platform by Daniele Rizzieri (2021)

GDBitflip [v1.04] Runtime fault injection platform by Daniele Rizzieri (2021) This platform executes N times a binary and during each execution it inj

Daniele Rizzieri 1 Dec 7, 2021
Runtime fault injection platform by Daniele Rizzieri

GDBitflip [v1.04] Runtime fault injection platform by Daniele Rizzieri (2021) This platform executes N times a binary and during each execution it inj

Daniele Rizzieri 1 Dec 7, 2021
Runtime profiler for Streamlit, powered by pyinstrument

streamlit-profiler ???? Runtime profiler for Streamlit, powered by pyinstrument. streamlit-profiler is a Streamlit component that helps you find out w

Johannes Rieke 23 Nov 30, 2022
A tool for checking if the external data used in Flatpak manifests is still up to date

Flatpak External Data Checker This is a tool for checking for outdated or broken links of external data in Flatpak manifests. Motivation Flatpak apps

Flathub 76 Dec 24, 2022
An integrated library for checking email if it is registered on social media

An integrated library for checking email if it is registered on social media

Sidra ELEzz 13 Dec 8, 2022
A module to prevent invites and joins to Matrix rooms by checking the involved server(s)' domain.

Synapse Domain Rule Checker A module to prevent invites and joins to Matrix rooms by checking the involved server(s)' domain. Installation From the vi

matrix.org 4 Oct 24, 2022
Similarity checking of sign languages

Similarity checking of sign languages This repository checks for similarity betw

Tonni Das Jui 1 May 13, 2022
A python script developed to process Windows memory images based on triage type.

Overview A python script developed to process Windows memory images based on triage type. Requirements Python3 Bulk Extractor Volatility2 with Communi

CrowdStrike 245 Nov 24, 2022
This is a a CSMA/CA simulator written in Python based on simulator of the same type

This is a a CSMA/CA simulator written in Python based on simulator of the same type found the link https://github.com/StevenSLXie/CSMA-Simulator with

M. Ismail 4 Nov 22, 2022