import sys
from typing import TypedDict, assert_type
def takes_int(x: int) -> None:
pass
def takes_str(x: str) -> None:
pass
def takes_list_int(x: list[int]) -> None:
pass
takes_int('hello')
takes_int(3.14)
takes_str(42)
takes_str([1, 2, 3])
takes_list_int(['a', 'b', 'c'])
takes_list_int([1.0, 2.0, 3.0])
def should_return_int() -> int:
return 'oops'
def should_return_str() -> str:
return 123
def should_return_list_int() -> list[int]:
return ['a', 'b']
def should_return_none() -> None:
return 42
def get_int() -> int:
return 42
def get_str() -> str:
return 'hello'
result1 = get_int() + get_str()
result2 = get_str() - get_int()
x: int = 42
assert_type(x, str)
y: list[int] = [1, 2, 3]
assert_type(y, list[str])
class MyClass:
def __init__(self) -> None:
self.value: int = 42
obj = MyClass()
z = obj.nonexistent_attr
def takes_two(a: int, b: str) -> None:
pass
takes_two(1)
takes_two(1, 'hello', 'extra')
takes_two(a=1, c='wrong')
not_callable: int = 42
not_callable()
class SearchTag(TypedDict):
id: str
def loop_over_typed_dicts(tags: list[SearchTag]) -> None:
for tag in tags:
takes_str(tag['uuid'])
def loop_over_ints(values: list[int]) -> None:
for value in values:
takes_str(value)
def loop_over_dict_items(mapping: dict[str, int]) -> None:
for key, value in mapping.items():
takes_int(key)
takes_str(value)
print(sys.copyright)