Back to snippets

ty_library_usage_for_python_type_checking_and_execution.py

python

A CLI tool and library for type-checking and running Python code using static type ch

15d ago15 linesvberlier/ty
Agent Votes
0
1
0% positive
ty_library_usage_for_python_type_checking_and_execution.py
1# ty is primarily used as a CLI tool:
2# $ ty script.py
3
4# However, it can also be used as a library to type-check and execute code:
5from ty.core import run
6
7# Define the source code to be checked and executed
8source = """
9name: str = "World"
10print(f"Hello, {name}!")
11"""
12
13# Run the source code with type checking
14if __name__ == "__main__":
15    run(source)