Skip to main content

annotyped

Annotyped is a simple library with utilities and decorators for type checking and type casting automatically on annotated functions at runtime.

pip install annotyped --user

The basics

# Simple typecheck, this uses the instance checker to check equality.
# You can set your own with `@annotyped.checkers.custom(callable)`


@annotyped.check
def add(a: int, b: int) -> int:
   return a + b


add(1, 2)      # 3
add(2, '10')   # Param 'b' requires type '<class 'int'>', found '<class 'str'>': '10'


# Simple typecast, this runs the annotation like it were an expression and uses the 
# result  `annotation(value)`

@annotyped.cast
def add(a: int, b: int) -> str:
   return a + b


add('10', '20')   # '30'
add(1, 2)         # '3'
add('1.1', 2)     # Param 'a' could not convert to '<class 'int'>' from '<class 'str'>': invalid literal for int() with base 10: '1.1'

Custom converters / casters

eg:

Convert from a tuple or a str into namedtuple.

import annotyped                                         
import math                                              
from collections import namedtuple                       

Position = namedtuple('Position', 'x, y')                


def position(pos):
   if isinstance(pos, str) and ',' in pos:
      pos = map(int, pos.split(','))
   return Position(*pos)


@annotyped.cast
def diff(p1: position, p2: position):                    
   return math.sqrt((p2.x - p1.x)**2 + (p2.y - p1.y)**2)


p1 = (10, 20)
p2 = '20,50'

print( diff(p1, p2) )

Metadata

Release files for annotyped 0.2.4

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

Source distribution (sdist)

Source distribution for annotyped 0.2.4
File Size Uploaded Provenance Actions
annotyped-0.2.4.tar.gz 3.1 kB Without provenance Details for annotyped-0.2.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for annotyped 0.2.4
File Interpreter ABI Platform Actions
annotyped-0.2.4-py3-none-any.whl Python 3 none any Details for annotyped-0.2.4-py3-none-any.whl

Total release size: 7.2 kB

Release files / annotyped-0.2.4.tar.gz

Download URL annotyped-0.2.4.tar.gz
Size 3.1 kB
Tags Source
SHA-256 checksum
How to use checksums
497f883d684d9e73829e312fdbcf254880775a4fc47da8eeabab817482162590
BLAKE2b-256 checksum
How to use checksums
7568e2b8268b5abfde5708ca0c76d5c8920d8a369fc8ceaf0d96904530cdd28b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.5

Release files / annotyped-0.2.4-py3-none-any.whl

Download URL annotyped-0.2.4-py3-none-any.whl
Size 4.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0950a378918f5e2ad67512a2eeec6ecfb2bdb471fc3f98e54a114327cec4bb51
BLAKE2b-256 checksum
How to use checksums
de339036529575d6fa7ff800f194890fee13aafc91c71ec4e42f82012c8ce00d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.5

Security for annotyped 0.2.4

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