Skip to main content

typed-everywhere

Runtime type checking and not only for function arguments and class variables but even for the ordinary local and global variables!

Installation

pip install typed-everywhere

How To Use

We have a proxy class:

class typed_everywhere.Typed(wrapped)

class @typed_everywhere.Typed(wrapped)

This class inherits a variant of ObjectProxy from wrapt. Along with all augmented assignment operators, this class also overloads the normal assignment operator (=) thanks to assign-overload. wrapped can be any object and the resulting instance of this class will act like wrapped in every way. If you use this class, you need to call typed_everywhere.patch_and_reload_module(). You can also access this function from assign_overload module. You can find documentation about this function in assign-overload. Usage example:

import typed_everywhere

def main():
    a = typed_everywhere.Typed(10)
    a = 20 # Ok
    print(a) # prints 20
    a = "abc" # Error

if typed_everywhere.patch_and_reload_module():
    main()

One thing to note is if you assign a variable holding a Typed instance to a new variable, new variable takes the value of the Typed instance, not the value of its underlying object. However, most operators return the underlying object. Example:

import typed_everywhere

def main():
    a = typed_everywhere.Typed(10)
    print(type(a+5)) # prints int
    b = a
    print(type(b)) # prints Typed

if typed_everywhere.patch_and_reload_module():
    main()

If you want to access the underlying object, use the __wrapped__ attribute:

import typed_everywhere

def main():
    a = typed_everywhere.Typed(10)
    b = a.__wrapped__
    print(type(b)) # prints int

if typed_everywhere.patch_and_reload_module():
    main()

Typed is also compatible with typeguard. Function argument type enforcement example:

import typeguard
import typed_everywhere

@typeguard.typechecked
def test4(a: typed_everywhere.Typed[int]):
    pass

def main():
    a = typed_everywhere.Typed(10)
    b = typed_everywhere.Typed("abc")
    test4(a) # Ok
    test4(b) # Error

if typed_everywhere.patch_and_reload_module():
    main()

Metadata

Release files for typed-everywhere 1.3.0

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

Source distribution (sdist)

Source distribution for typed-everywhere 1.3.0
File Size Uploaded
typed_everywhere-1.3.0.tar.gz 2.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for typed-everywhere 1.3.0
File Interpreter ABI Platform
typed_everywhere-1.3.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 5.9 kB

Release files / typed_everywhere-1.3.0.tar.gz

Download URL typed_everywhere-1.3.0.tar.gz
Size 2.7 kB
Tags Source
SHA-256 checksum
How to use checksums
efb78c93433701bbc300340264281e81c82ae828c1178dcb8a4a8d7aa744e7dc
BLAKE2b-256 checksum
How to use checksums
cb49689621f8ba645623c787d18549706264988161ae869b804fdfe5e211f1bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.0

Release files / typed_everywhere-1.3.0-py2.py3-none-any.whl

Download URL typed_everywhere-1.3.0-py2.py3-none-any.whl
Size 3.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
b911e196a04ffe337b435e5c9af3c97623709119705de3701245781ceeec0a92
BLAKE2b-256 checksum
How to use checksums
918e92f260c85d1c27aee59f5e515f188103c06b93c80679fc69d914d1a3a4b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.0

Release history Release notifications | RSS feed

This release

1.3.0 This release

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release 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