Typhon

Meet the language.

Write typed .ty source, check it with tyc and build readable Python. These are the language rules and the code you deploy.

What you deploy is Python

The compiler writes readable Python for CPython 3.13+: dataclasses, PEP 695 generics, match and asyncio. You do not install the compiler in production. Features such as Result generate Python helpers alongside your output.

src/dashboard.ty · excerpt
async def dashboard(uid: UserId) -> str:
    gather:
        user = fetch_user(uid)
        posts = fetch_posts(uid)
    return f"{user.name}: {len(posts)} posts"
build/dashboard.py · emitted excerpt
async def dashboard(uid: UserId) -> str:
    async with asyncio.TaskGroup() as __typhon_tg_0__:
        __typhon_gather_1__ = __typhon_tg_0__.create_task(fetch_user(uid))
        __typhon_gather_2__ = __typhon_tg_0__.create_task(fetch_posts(uid))
    user = __typhon_gather_1__.result()
    posts = __typhon_gather_2__.result()
    return f"{user.name}: {len(posts)} posts"

Real output from tyc 1.0.0-beta.7. gather: runs independent awaits on a TaskGroup, so if one fails the rest are cancelled. View the complete example, including its types and functions.

src/config.ty · excerpt
def configure(raw_port: str) -> Result[int, str]:
    let port: int = parse_port(raw_port)?
    return Ok(port)
build/config.py · emitted excerpt
def configure(raw_port: str) -> Result[int, str]:
    __typhon_q_0__ = parse_port(raw_port)
    if isinstance(__typhon_q_0__, __typhon_Err__):
        return __typhon_q_0__
    port: int = __typhon_q_0__.value
    return Ok(port)

? propagates a failure inside a function returning Result. The build includes the generated helper imports. View the complete configuration example.

What tyc refuses to compile

Checks for nullability, exhaustiveness and explicit type contracts. Browse the diagnostic catalogue for explanations, examples and fixes, or use tyc explain for offline help.

  • nullable_use

    A value that might be None is used where it can't be.

    greet(find_user(2))
  • non_exhaustive_match

    A match over a sealed union skips one of its variants.

    case Circle(r): …  # no Square
  • immutable_assign

    Something declared with let is assigned again.

    let n: int = 1
    n = 2
  • missing_await

    Synchronous code calls an async function and drops the coroutine.

    let u = fetch_user(1)
  • result_error_mismatch

    A ? passes on an error type the function never declared.

    parse(raw)?
  • missing_annotation

    A parameter or return type has no annotation.

    def add(a, b):

Browse the diagnostic guide

The eight rules

The conventions that make types, mutation and failure explicit.

  1. Every parameter and return type is annotated.There is no inference fallback and no implicit Any.
  2. Local names are declared with let or mut.let cannot be reassigned. Use mut when you mean to.
  3. A plain type cannot hold None.Write str? when it can, and narrow it before use.
  4. Methods live in impl blocks.Classes hold data, and their constructors are generated.
  5. Any only comes in through unsafe: or .dty stubs.An as! cast checks the shape at runtime instead.
  6. A match over a sealed union is exhaustive.Add a variant and every match that misses it fails.
  7. Represent expected errors with Result[T, E].Propagate them with ?, and turn exceptions into values at the edges.
  8. A let declared without a value is assigned before use.Reading it on a path that never assigned it is an error.

Learn the rest

Try the complete examples, or follow the language tour. If you have typed Python already, tyc migrate gives you a starting point; review and check its output as you adopt the language.

Learn it by writing it.

Follow the language tour, one working example at a time.