ty: Astral이 만든 천둥같이 빠른 Python Type Checker (Ruff & uv 제작자)
I’m happy to translate the article for you, but I’ll need the full text you’d like translated. Could you please paste the content (excluding the source line you’ve already provided) here? Once I have the article, I’ll keep the source link unchanged and translate the rest into Korean while preserving all formatting, markdown, and technical terms.
주요 기능
- ⚡ 번개처럼 빠름 – mypy와 Pyright보다 10–100배 빠름
- 🔍 풍부한 진단 – 다중 파일 컨텍스트를 포함한 상세 오류 메시지
- 🧠 스마트 타입 추론 – 타입 어노테이션이 없어도 버그를 잡아냄
- 🎯 고급 타입 시스템 – 교차 타입, 고급 좁히기, 도달 가능성 분석
- 🛠️ 언어 서버 – IDE 통합을 위한 내장 지원 (VS Code 확장 제공)
설치
# Using uv (recommended)
uv tool install ty@latest
# Using pip
pip install ty
기본 사용법
# Check a file
ty check file.py
# Check directories
ty check src tests
# Verbose mode
ty check src --verbose
Source:
ty가 특별한 이유는?
1. 중요한 속도
ty는 전체 Home Assistant 프로젝트를 ~2.19 초 만에 타입‑체크할 수 있습니다. 이는 mypy의 45.66 초와 비교했을 때 20배 이상 빠른 속도입니다!
대규모 코드베이스에서는 이 속도 차이가 개발자 경험을 크게 바꿔줍니다:
- CI가 끝날 때까지 기다릴 필요가 없습니다
- IDE에서 즉시 피드백을 받을 수 있습니다
- 저장할 때마다 실행해도 실용적입니다
2. 강력한 타입 추론
ty는 타입 어노테이션이 없어도 버그를 찾아낼 수 있습니다. 아래는 실제 사례들입니다.
실제 버그 탐지
예시 1: 타입 불일치
def add(x: int, y: int) -> int:
return x + y
result: str = add(1, 2) # Oops! Assigning int to str
ty의 출력
error[invalid-assignment]: Object of type `int` is not assignable to `str`
--> example.py:4:9
|
4 | result: str = add(1, 2)
| --- ^^^^^^^^^ Incompatible value of type `int`
| |
| Declared type
예시 2: 누락된 속성
class User:
def __init__(self, name: str):
self.name = name
def get_email(self):
return self.email # email was never defined!
ty가 잡아냅니다
error[unresolved-attribute]: Object of type `Self@get_email` has no attribute `email`
--> example.py:6:16
|
6 | return self.email
| ^^^^^^^^^^
더 복잡한 경우도 마찬가지입니다:
class DatabaseClient:
def __init__(self, connection_string: str):
self.connection = connect(connection_string)
def query(self, sql: str):
# Typo: should be .execute(), not .exec()
return self.connection.exec(sql)
ty는 .exec() 메서드가 연결 객체에 존재하지 않음을 경고합니다.
예시 3: 잘못된 함수 인자
numbers: list[int] = [1, 2, 3]
numbers.append("four") # String in int list!
ty의 오류
error[invalid-argument-type]: Argument to bound method `append` is incorrect
--> example.py:2:16
|
2 | numbers.append("four")
| ^^^^^^ Expected `int`, found `Literal["four"]`
예시 4: 널 안전성
def process(value: str | None) -> int:
return len(value) # What if value is None?
ty가 문제를 찾아냅니다
error[invalid-argument-type]: Expected `Sized`, found `str | None`
--> example.py:2:16
|
2 | return len(value)
| ^^^^^
|
info: Element `None` of this union is not assignable to `Sized`
예시 5: 암시적 None 반환
def get_name(user_id: int) -> str:
if user_id > 0:
return "User"
# Missing return statement – implicit None!
ty도 이를 잡아냅니다
error[invalid-return-type]: Function can implicitly return `None`,
which is not assignable to return type `str`
구성
ty는 설정에 pyproject.toml을 사용합니다:
[tool.ty]
[tool.ty.environment]
python-version = "3.10"
[tool.ty.src]
include = ["src/**/*.py", "tests/**/*.py"]
exclude = [".tox/**", "build/**", "dist/**"]
# Per‑directory overrides
[[tool.ty.overrides]]
include = ["tests/**/*.py"]
[tool.ty.overrides.rules]
invalid-assignment = "ignore" # More lenient for tests
Source:
CI/CD 통합
GitHub Actions
name: Type Check
on: [push, pull_request]
jobs:
typecheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install dependencies
run: pip install ty
- name: Run type checker
run: ty check src tests
tox 통합
[testenv:ty]
deps =
ty
-e .
commands =
ty check src tests
pre‑commit 훅
repos:
- repo: local
hooks:
- id: ty
name: ty type checker
entry: ty check src tests
language: system
pass_filenames: false
types: [python]
Python 프로젝트에 ty가 가져다 주는 속도와 안전성을 누리세요!
Editor Integration
VS Code
- Install the “ty” extension from the VS Code Marketplace.
Enjoy automatic:
- Type checking as you type
- Inlay hints for inferred types
- Code actions and quick fixes
- Jump‑to‑definition with type awareness
ty vs mypy vs Pyright
| Feature | ty | mypy | Pyright |
|---|---|---|---|
| 속도 | ⚡⚡⚡ 초고속 | 🐢 보통 | 🚀 빠름 |
| 언어 | Rust | Python | TypeScript |
| 오류 메시지 | 📝 매우 상세함 | 📄 표준 | 📝 상세함 |
| 타입 추론 | 🧠 강력함 | 📚 표준 | 🧠 강력함 |
| 성숙도 | 🆕 베타 | ✅ 안정적 | ✅ 안정적 |
| 진단 | 🔍 다중 파일 컨텍스트 | 📊 단일 파일 | 🔍 교차 파일 |
| 언어 서버 | ✅ 내장 | ⚠️ dmypy를 통해 | ✅ 내장 |
현재 제한 사항
As of v0.0.9 (Beta):
- 제한된 규칙 집합 – 주요 규칙이 구현되었으며, 2026년에 더 추가될 예정입니다.
- 아직 엄격 모드 없음 – 타입 어노테이션이 없다고 불평하지 않습니다.
- 베타 상태 – 안정적인 릴리스 전에 API가 변경될 수 있습니다.
베타 단계에서도 ty는 이미 실제 버그를 잡아내며, 프로덕션 코드베이스에 가치를 제공합니다.
ty 시작하기
단계 1: 설치 및 실행
uv tool install ty@latest
ty check src
단계 2: 결과 검토
ty는 타입 어노테이션이 없어도 코드에 실제 버그를 보여줍니다!
단계 3: CI에 추가
# 테스트 스크립트에 추가
tox -e ty
# 직접 실행
ty check src tests
단계 4: 점진적 타입 어노테이션
# Before
def calculate_total(items):
return sum(item.price for item in items)
# After
def calculate_total(items: list[Item]) -> Decimal:
return sum(item.price for item in items)
어노테이션을 사용하면 ty가 더욱 강력해집니다!
실제 예시: FastAPI 애플리케이션
from fastapi import FastAPI, HTTPException
app = FastAPI()
class UserService:
def __init__(self, db_url: str):
self.db = connect_database(db_url)
def get_user(self, user_id: int):
user = self.db.query(User).filter(User.id == user_id).first()
if user:
return user
# Bug: FastAPI expects HTTPException, but we're returning None!
return None
@app.get("/users/{user_id}")
async def get_user(user_id: int):
service = UserService(DB_URL)
user = service.get_user(user_id)
# Bug: user could be None, but we're accessing .dict()
return user.dict()
ty는 두 가지 버그를 모두 잡아냅니다:
get_user가None을 반환할 수 있지만, FastAPI는 예외 또는 유효한 사용자를 기대합니다.user가None일 경우user.dict()호출이 실패할 수 있습니다.
성능 팁
- 파일 제외 사용 – 생성된 파일과 vendor 디렉터리를 건너뛰세요.
- 캐시 활성화 –
ty는 변경되지 않은 파일에 대한 결과를 캐시합니다. - 병렬 처리 –
ty는 자동으로 여러 코어를 사용합니다. - 증분 모드 – 편집기에서 변경된 파일만 다시 검사됩니다.
로드맵
Astral에 따르면, ty는 2026년에 안정적인 1.0 릴리스를 목표로 하며, 다음과 같은 계획이 있습니다:
- ✅ 보다 포괄적인 규칙 커버리지
- ✅ 엄격 모드 (타입 주석 강제)
- ✅ 인기 프레임워크와의 더 나은 통합
- ✅ 커스텀 규칙을 위한 플러그인 시스템
- ✅ 성능 최적화
결론
ty는 Python 타입 검사의 차세대 진화를 나타냅니다. 뛰어난 속도, 강력한 추론, 그리고 훌륭한 진단 기능을 결합하여 Python 개발자에게 매력적인 선택이 됩니다.
아직 베타 단계이지만, ty는 실제 버그를 잡고 코드 품질을 향상시키는 데 이미 가치가 입증되고 있습니다. mypy나 Pyright를 사용하면서 느린 검사 시간에 좌절하고 있다면, ty를 시도해 볼 가치가 있습니다.
Astral 팀은 Ruff와 uv에서 뛰어난 실적을 보였으며, ty도 Python 툴링 생태계에서 또 다른 게임 체인저가 될 것으로 보입니다.
리소스
- 🌐 공식 웹사이트:
- 📚 문서:
- 💻 GitHub:
- 💬 디스코드:
아직 ty를 사용해 보셨나요? 파이썬 타입 체커에 대한 경험은 어떠신가요? 댓글에 알려 주세요! 👇