Skip to content

Commit 2e5d593

Browse files
committed
Provide solutions to basic challenges laike9m#19
1 parent 69b3a44 commit 2e5d593

File tree

9 files changed

+68
-1
lines changed

9 files changed

+68
-1
lines changed

challenges/basic-any/solution.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from typing import Any
2+
3+
4+
def foo(x: Any):
5+
pass
6+
7+
8+
## End of your code ##
9+
foo(1)
10+
foo("10")
11+
foo(1, 2) # expect-type-error

challenges/basic-dict/solution.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def foo(x: dict[str, str]):
2+
pass
3+
4+
5+
## End of your code ##
6+
foo({"foo": "bar"})
7+
foo({"foo": 1}) # expect-type-error

challenges/basic-list/solution.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def foo(x: list[str]):
2+
pass
3+
4+
5+
## End of your code ##
6+
foo(["foo", "bar"])
7+
foo(["foo", 1]) # expect-type-error

challenges/basic-optional/solution.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def foo(x: int | None = 0):
2+
pass
3+
4+
5+
## End of your code ##
6+
foo(10)
7+
foo()
8+
9+
foo("10") # expect-type-error
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
def foo(x: int):
2+
pass
3+
4+
5+
## End of your code ##
6+
foo(10)
7+
8+
foo("10") # expect-type-error

challenges/basic-return/solution.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def foo() -> int:
2+
return 1
3+
4+
5+
## End of your code ##
6+
from typing import assert_type
7+
8+
assert_type(foo(), int)
9+
assert_type(foo(), str) # expect-type-error

challenges/basic-tuple/solution.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def foo(x: tuple[str, int]):
2+
pass
3+
4+
5+
## End of your code ##
6+
foo(("foo", 1))
7+
8+
foo((1, 2)) # expect-type-error
9+
foo(("foo", "bar")) # expect-type-error
10+
foo((1, "foo")) # expect-type-error

challenges/basic-variable/solution.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
a: int
2+
3+
4+
## End of your code ##
5+
a = 2
6+
a = "1" # expect-type-erro

challenges/basic-callable/question.py renamed to challenges/intermediate-callable/question.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
TODO:
33
44
Define a callable type that accepts a string parameter and returns None.
5-
*The parameter name can be any.*
5+
*The parameter name can be arbitrary.*
66
"""
77

88
SingleStringInput = ...

0 commit comments

Comments
 (0)