Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions python-ty/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Astral's ty: A New Blazing-Fast Type Checker for Python

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/).
28 changes: 28 additions & 0 deletions python-ty/adder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# fmt:off

import warnings

type Number = int | float


def new_adder(x: Number, y: Number) -> Number:
return x + y


@warnings.deprecated("Use the new_adder() instead")
def legacy_adder(x, y):
return x + y


if __name__ == "__main__":
legacy_adder( # ty: ignore
42,
555
)

legacy_adder(
42,
555
) # ty: ignore

new_adder(a=42, b=555) # ty: ignore[unknown-argument, missing-argument]
9 changes: 9 additions & 0 deletions python-ty/cross_platform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from sys import platform
from typing import reveal_type

if platform == "win32":
x = "Windows"
else:
x = "macOS or Linux"

reveal_type(x)
3 changes: 3 additions & 0 deletions python-ty/python_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from typing import Literal

type Size = Literal["S", "M", "L", "XL"]