Skip to content

Commit 2e26daf

Browse files
committed
Materials for Astral's ty tutorial
1 parent dfc0e2c commit 2e26daf

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

python-ty/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Astral's ty: A New Blazing-Fast Type Checker for Python
2+
3+
This folder contains sample code for the Real Python tutorial [Astral's ty: A New Blazing-Fast Type Checker for Python](https://realpython.com/python-ty/).

python-ty/adder.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import warnings
2+
3+
type Number = int | float
4+
5+
6+
def new_adder(x: Number, y: Number) -> Number:
7+
return x + y
8+
9+
10+
@warnings.deprecated("Use the new_adder() instead")
11+
def legacy_adder(x, y):
12+
return x + y
13+
14+
15+
if __name__ == "__main__":
16+
legacy_adder(42, 555) # ty: ignore
17+
18+
legacy_adder(42, 555) # ty: ignore
19+
20+
new_adder(a=42, b=555) # ty: ignore[unknown-argument, missing-argument]

python-ty/cross_platform.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from sys import platform
2+
from typing import reveal_type
3+
4+
if platform == "win32":
5+
x = "Windows"
6+
else:
7+
x = "macOS or Linux"
8+
9+
reveal_type(x)

python-ty/python_version.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from typing import Literal
2+
3+
type Size = Literal["S", "M", "L", "XL"]

0 commit comments

Comments
 (0)