Skip to content

Commit 8e4a5c8

Browse files
authored
Merge pull request #694 from realpython/python-ty
Materials for Astral's ty tutorial
2 parents 61dc040 + 0ae5b15 commit 8e4a5c8

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# fmt:off
2+
3+
import warnings
4+
5+
type Number = int | float
6+
7+
8+
def new_adder(x: Number, y: Number) -> Number:
9+
return x + y
10+
11+
12+
@warnings.deprecated("Use the new_adder() instead")
13+
def legacy_adder(x, y):
14+
return x + y
15+
16+
17+
if __name__ == "__main__":
18+
legacy_adder( # ty: ignore
19+
42,
20+
555
21+
)
22+
23+
legacy_adder(
24+
42,
25+
555
26+
) # ty: ignore
27+
28+
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)