Skip to content

Commit 230bb2c

Browse files
committed
Add a challenge about variance
1 parent f601242 commit 230bb2c

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""
2+
Annotate function `f` and `g`, to make tests pass.
3+
"""
4+
5+
6+
def f(a):
7+
pass
8+
9+
10+
def g(a):
11+
pass
12+
13+
14+
## End of your code ##
15+
16+
l1: list[int] = [1, 2]
17+
f(l1) # expect-type-error
18+
g(l1)
19+
20+
l2: list[int | str] = [1, 2]
21+
f(l2)
22+
g(l2)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
Annotate function `f` and `g`, to make tests pass.
3+
"""
4+
5+
from collections.abc import Sequence
6+
7+
8+
def f(a: list[int | str]):
9+
pass
10+
11+
12+
def g(a: Sequence[int | str]):
13+
pass
14+
15+
16+
## End of your code ##
17+
18+
l1: list[int] = [1, 2]
19+
f(l1) # expect-type-error
20+
g(l1)
21+
22+
l2: list[int | str] = [1, 2]
23+
f(l2)
24+
g(l2)

0 commit comments

Comments
 (0)