Skip to main content

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

Project description

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

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

typethon-0.0.2.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

typethon-0.0.2-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file typethon-0.0.2.tar.gz.

File metadata

  • Download URL: typethon-0.0.2.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for typethon-0.0.2.tar.gz
Algorithm Hash digest
SHA256 a8444e450af6f353766cfd52d02f9fa76ec805da633def8abcf80492f1db1ed6
MD5 010f623e59dbe28bfac7c9ea6ca85519
BLAKE2b-256 b23280bea6efd91187815a36b2172a1e5bd7b30ac3ae2da6c2a19af6bdbc71a7

See more details on using hashes here.

File details

Details for the file typethon-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: typethon-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for typethon-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 27cd920659f042c0db610a252ed8501bcc7ccf739fc212042b449d60de5e9a1d
MD5 c8e7907c1c02d6cb6c9a63d437d0b328
BLAKE2b-256 d7a367a325694054b1b3bd6b6f7f3d3afadedd3b596647b083e5bca8b65a6d38

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page