Skip to main content

Typethon

100% pure any color, so long as it's black wheel, yes pypi version pypi downloads

Typethon is an extremely lightweight and simple module for strongly typed Python.

Typethon has zero dependencies, nada, zilch! Typethon doesn't even use imports from the standard library! (except for argument parsing in the CLIs, but they are completely optional and only provide linting / building functionality)

(There are dependencies for development and building, but they are not acquired on installing Typethon.)

Installation from PyPI

  1. Install via pip: pip install typethon

Decorator Example

from typethon.decorators import *

@ReturnType(types=int, constraints=(lambda x: x > 0), use_arg_passing=False) # ReturnType must go before if disabling arg passing, although I have not found a reason for a user to do so
@ArgumentTypes(types={"a": int, "b": int}, constraints={"a": (lambda x: x > 0, lambda x: x < 10), "b": (lambda x: x > 0, lambda x: x < 10)}, use_arg_passing=False)
def constrained_add(a, b):
    return a + b

@ArgumentTypes(use_annotations=True, constraints={"b": (lambda x: x > 0, lambda x: x <= 100)})
@ReturnType(types=type(None)) # must use NoneType to specify we actually want to restrict the return type to None, not just have no restriction
def multiplier_procedure(a: str, b: int):
    print(a * b)

@ReturnType(use_annotations=True)
def silent_procedure() -> None: # the annotation parser handles None to NoneType conversion automagically here
    print("Hello World!")

@Strict() # syntactic sugar for @ArgumentTypes(use_annotations=True) combined with @ReturnType(use_annotations=True), this does not accept any arguments
def strict_uppercase(a:str) -> str:
    print(a)
    return a.upper()

@Strict(arg_constraints={"a": (lambda x: x > 0, lambda x: x < 5)}, return_constraints=(lambda x: x > 0, lambda x: x < 10)) # Strict also accepts constraints, denoted as separate arguments
def strict_constrained_multiply(a:int) -> int:
    print(a)
    return a * 2

print(constrained_add(1,2))
multiplier_procedure("hello", 3)
silent_procedure()
print(strict_uppercase("hi!"))
strict_constrained_multiply(4)

Development

  1. Clone the repository: git clone https://github.com/obfuscatedgenerated/Typethon.git
  2. (optional but recommended) Create a virtual environment: python -m venv env (or python3 -m venv env) and then activate it: .\env\Scripts\activate (or source env/bin/activate)
  3. Install build/dev dependencies: pip install -r requirements.txt
  4. Once you've made changes, add yourself as a contributor: python build_tool.py add_contributor <your username> then commit and make a PR.
  • VSCode users: it's recommended to use the Pylance language server as opposed to the Jedi language server as Jedi has issues with wrapper functions when displaying function signatures. You can do this by installing the Pylance extension and changing/setting the python.languageServer to Pylance in your settings.json file.

Building

  1. Make sure all build/dev dependencies are installed: pip install -r requirements.txt
  2. From your virtual environment (if you used one, otherwise just run as usual): python build_tool.py build

Metadata

Release files for typethon 0.0.2

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

Source distribution (sdist)

Source distribution for typethon 0.0.2
File Size Uploaded
typethon-0.0.2.tar.gz 10.9 kB Details

Built distribution (wheel)

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

Total release size: 20.7 kB

Release files / typethon-0.0.2.tar.gz

Download URL typethon-0.0.2.tar.gz
Size 10.9 kB
Tags Source
SHA-256 checksum
How to use checksums
a8444e450af6f353766cfd52d02f9fa76ec805da633def8abcf80492f1db1ed6
BLAKE2b-256 checksum
How to use checksums
b23280bea6efd91187815a36b2172a1e5bd7b30ac3ae2da6c2a19af6bdbc71a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.10.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.5

Release files / typethon-0.0.2-py3-none-any.whl

Download URL typethon-0.0.2-py3-none-any.whl
Size 9.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
27cd920659f042c0db610a252ed8501bcc7ccf739fc212042b449d60de5e9a1d
BLAKE2b-256 checksum
How to use checksums
d7a367a325694054b1b3bd6b6f7f3d3afadedd3b596647b083e5bca8b65a6d38
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.10.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.5

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

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