-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_type_checking.py
More file actions
26 lines (18 loc) · 852 Bytes
/
test_type_checking.py
File metadata and controls
26 lines (18 loc) · 852 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from typing import List, Dict
def add(a: int, b: int) -> int:
return a + b
def greet(name: str) -> str:
return f"Hello, {name}!"
def get_item(data: List[int], index: int) -> int:
return data[index]
def make_dict(keys: List[str], values: List[int]) -> Dict[str, int]:
return dict(zip(keys, values))
# Intentional type errors below
def add_error(a: int, b: int) -> int:
return a + "b" # This should raise a type error
def greet_error(name: str) -> str:
return f"Hello, {name + 123}!" # This should raise a type error
def get_item_error(data: List[int], index: int) -> str:
return data[index] # This should raise a type error (return type mismatch)
def make_dict_error(keys: List[str], values: List[int]) -> Dict[str, str]:
return dict(zip(keys, values)) # This should raise a type error (return type mismatch)