TypedPython
Ordinary typed Python, checked at build time and compiled ahead of time, with CPython's exact semantics.평범한 타입 붙은 Python을 빌드할 때 검사하고 미리 컴파일합니다. 의미는 CPython과 정확히 같습니다.
Overview개요
TypedPython lives inside python-multiplatform and does two things. A soundness gate runs in the build: the project's Python is type-checked, and a value whose type leaks to Any is an error, not a warning. An ahead-of-time compiler turns typed functions into C and ships them as ordinary CPython extension modules inside the app. No new syntax, no new language: a function compiles or stays in the interpreter, one function at a time.
TypedPython은 python-multiplatform 안에서 두 가지를 합니다. 빌드 안에서 건전성 게이트가 돕니다. 프로젝트의 Python을 타입 검사하고, 타입이 Any로 새는 값은 경고가 아니라 오류입니다. 미리 컴파일하는 컴파일러는 타입 붙은 함수를 C로 바꿔 앱 안의 평범한 CPython 확장 모듈로 배포합니다. 새 문법도 새 언어도 없고, 함수 하나씩 컴파일되거나 인터프리터에 남습니다.
The problem it solves푸는 문제
Two pressures meet here. In the age of AI agents, a language without types gives an agent nothing to check before it runs the code, which is where Rust and TypeScript pull ahead; TypedPython makes Python agent-first by putting a type gate in the build and a compiler behind it. And fast Python today means one of three things, none of which works for apps on every platform. C extensions are a second language and do not exist for most mobile targets. Cython and numba are fast mostly in modes that switch Python's rules off: integers that wrap, bounds that go unchecked, globals frozen at compile time. numba is a JIT, which iOS forbids and native images cannot carry. LPython is a separate language implementation, not an extension for the CPython inside an app.
두 가지 압력이 여기서 만납니다. AI 에이전트 시대에 타입이 없는 언어는 에이전트가 코드를 실행하기 전에 확인할 것을 주지 못하고, 그 자리에서 Rust와 TypeScript가 앞서 나갑니다. TypedPython은 빌드에 타입 게이트를 두고 그 뒤에 컴파일러를 두어 Python을 에이전트 우선으로 만듭니다. 그리고 오늘날 빠른 Python은 셋 중 하나이고, 모든 플랫폼의 앱에서 되는 것은 없습니다. C 확장은 두 번째 언어이고 대부분의 모바일 타깃에는 없습니다. Cython과 numba가 빠른 것은 대부분 Python의 규칙을 끄는 모드에서입니다. 정수가 한 바퀴 돌고, 경계를 검사하지 않고, 전역을 컴파일할 때 얼립니다. numba는 JIT라서 iOS가 금지하고 네이티브 이미지가 품을 수 없습니다. LPython은 별도의 언어 구현이지 앱 안의 CPython을 위한 확장이 아닙니다.
How it works동작 방식
- Integers are machine words while an interval proof says they fit, and big integers the moment they might not.
- Arrays of numbers are read into native buffers and written back, with bounds checks removed only where proved redundant.
- Classes are compiled with guards on the type version tag and a dictionary watcher, so a monkey-patched class falls back to the interpreter.
- Calls into compiled code take a fast entry when the arguments match and the general path otherwise; nothing raises early.
- Long loops poll CPython's own eval breaker, so signals, pending calls and thread switches happen as they would in the interpreter.
- 정수는 구간 증명이 맞다고 하는 동안 기계어 크기이고, 넘칠 수 있는 순간 큰 정수가 됩니다.
- 숫자 배열은 네이티브 버퍼로 읽었다가 다시 쓰고, 경계 검사는 필요 없다고 증명된 곳에서만 없앱니다.
- 클래스는 타입 버전 태그 검사와 딕셔너리 감시자를 붙여 컴파일해서, 실행 중에 클래스를 고치면 인터프리터로 돌아갑니다.
- 호출은 인자가 맞으면 빠른 입구로, 아니면 일반 경로로 들어가고, 미리 예외를 내지 않습니다.
- 긴 루프는 CPython 자신의 eval breaker를 확인해서 시그널, 대기 중인 호출, 스레드 전환이 인터프리터에서처럼 일어납니다.
Design decisions설계 결정
- Equivalence is the contract. Results, exceptions and observable behaviour match CPython. The only exception, decided explicitly, is the timing of garbage collection, which the language reference leaves to the implementation.
- Speed by proof. No fast-math mode that changes floating-point results.
- Ahead of time. Runs on iOS, Android and in GraalVM native images.
- Gaps closed in order: faster call entry and inlining, interval proofs, zero-copy buffers, string and dict fast paths, virtual objects, parallel loops.
- 동일성이 계약입니다. 결과, 예외, 관측 가능한 동작이 CPython과 같습니다. 명시적으로 정한 예외는 언어 레퍼런스가 구현에 맡긴 가비지 컬렉션 시점 하나입니다.
- 증명으로 얻는 속도. 실수 계산 결과를 바꾸는 fast-math 모드는 두지 않습니다.
- 미리 컴파일. iOS, Android, GraalVM 네이티브 이미지에서 돕니다.
- 메우는 순서: 빠른 호출 입구와 인라인, 구간 증명, 복사 없는 버퍼, 문자열과 딕셔너리 빠른 경로, 가상 객체, 병렬 루프.
Where it fits생태계 안의 위치
Its gate runs in the Gradle build through python-multiplatform's plugin; its compiled modules ship through pypackpack's native and mixed build levels. pythonx-graphics uses it for per-frame logic and pythonx-concurrent for parallel work on free-threaded CPython.
게이트는 python-multiplatform의 플러그인을 통해 Gradle 빌드에서 돌고, 컴파일 모듈은 pypackpack의 native와 mixed 빌드 레벨로 배포됩니다. pythonx-graphics는 매 프레임 로직에, pythonx-concurrent는 free-threaded CPython의 병렬 작업에 씁니다.
Where it stands현재 상태
| Benchmark | Speed-up over CPython | Note |
|---|---|---|
| fannkuch | Rust parity | |
| nbody | 31x | about 2x from Rust |
| spectral-norm | 6.3x | goal 10x |
Working: the gate, the compiler on desktop, compiled classes, the CPython test of equivalence (more than 950 cases). In progress: free-threaded code generation on 3.15t, verified to keep the GIL off after import.
| 벤치마크 | CPython 대비 | 비고 |
|---|---|---|
| fannkuch | Rust와 대등 | |
| nbody | 31배 | Rust와 약 2배 차이 |
| spectral-norm | 6.3배 | 목표 10배 |
동작: 게이트, 데스크톱 컴파일러, 클래스 컴파일, CPython 동일성 테스트(950개 이상). 진행 중: 3.15t의 free-threaded 코드 생성. import 뒤에도 GIL이 꺼진 상태로 남는 것을 확인했습니다.
Future design미래 설계
- Free-threaded by construction. The compiler knows which objects a function owns, locks only shared ones with CPython's critical sections, and declares its modules safe without the GIL.
- Parallel loops whose iterations are proven independent run across cores.
- Virtual objects: short-lived objects are not allocated unless something could observe them.
- The end of C extensions for most code: typed Python becomes the way to make Python fast, on every platform.
- 처음부터 free-threaded. 컴파일러는 함수가 소유한 객체를 알아서 공유되는 것만 CPython의 critical section으로 잠그고, 모듈이 GIL 없이 안전하다고 선언합니다.
- 병렬 루프. 반복이 독립이라고 증명된 루프는 여러 코어에서 돕니다.
- 가상 객체. 짧게 사는 객체는 무언가 관측할 수 있을 때만 만듭니다.
- 대부분의 코드에서 C 확장의 끝. 타입 붙은 Python이 모든 플랫폼에서 Python을 빠르게 하는 방법이 됩니다.
Roadmap로드맵
- M1, 2026-10-17: the gate as a default build step.
- M2, 2026-11-07: desktop compiler targets (spectral-norm 10x, trace events).
- M3, 2026-11-30: compiled modules shipped through pypackpack, usable in apps.
- M1, 2026-10-17: 게이트를 기본 빌드 단계로.
- M2, 2026-11-07: 데스크톱 컴파일러 목표(spectral-norm 10배, trace 이벤트).
- M3, 2026-11-30: pypackpack으로 배포되는 컴파일 모듈, 앱에서 사용 가능.