python-typewriter

Typewriter

Typewriter is a Typer CLI built on LibCST that normalizes None-related type annotations in Python source code.

The hosted docs on Read the Docs publish the default branch as latest and tagged releases as stable/versioned documentation, so the docs stay aligned with project releases without committing generated HTML to the repository.

What Typewriter rewrites

Default mode keeps output Python 3.9-compatible:

Union[T, None] -> Optional[T]
Union[T1, T2, None] -> Optional[Union[T1, T2]]
x: T = None -> x: Optional[T] = None
def f(x: T = None) -> def f(x: Optional[T] = None)

With --target-version 3.10 or newer, Typewriter emits PEP 604 unions instead:

Union[T, None] -> T | None
Optional[T] -> T | None
Union[T1, T2] -> T1 | T2
Union[T1, T2, None] -> T1 | T2 | None
x: T = None -> x: T | None = None
def f(x: T = None) -> def f(x: T | None = None)

Highlights