Skip to content

Commit 6a41bf4

Browse files
committed
make error explicit in double_protocol_wrong.py
and other minor fixes
1 parent f3b564c commit 6a41bf4

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.idea/
2+
13
# Byte-compiled / optimized / DLL files
24
__pycache__/
35
*.py[cod]

Diff for: double/double_protocol_ok_py312.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from typing import Protocol
2+
3+
4+
# T = TypeVar('T') # <1>
5+
6+
class Repeatable(Protocol):
7+
def __mul__[T](self: T, repeat_count: int) -> T: ... # <2>
8+
9+
10+
# RT = TypeVar('RT', bound=Repeatable) # <3>
11+
12+
def double[RT: Repeatable](x: RT) -> RT: # <4>
13+
return x * 2

Diff for: double/double_protocol_wrong.py

+5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22

33
T = TypeVar('T') # <1>
44

5+
56
class Repeatable(Protocol):
67
def __mul__(self: T, repeat_count: int) -> T: ... # <2>
78

9+
810
def double(x: Repeatable) -> Repeatable: # <3>
911
return x * 2
12+
13+
14+
y = double(3) + 4 # <4>

Diff for: double/double_sequence.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from collections import abc
1+
from collections.abc import Sequence
22
from typing import TypeVar
33

44
T = TypeVar('T')
55

6-
def double(x: abc.Sequence[T]) -> Sequence[T]:
6+
def double(x: Sequence[T]) -> Sequence[T]:
77
return x * 2

0 commit comments

Comments
 (0)