Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6a41bf4

Browse files
committed
make error explicit in double_protocol_wrong.py
and other minor fixes
1 parentf3b564c commit6a41bf4

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

‎.gitignore

Lines changed: 2 additions & 0 deletions
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]

‎double/double_protocol_ok_py312.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
fromtypingimportProtocol
2+
3+
4+
# T = TypeVar('T') # <1>
5+
6+
classRepeatable(Protocol):
7+
def__mul__[T](self:T,repeat_count:int)->T: ...# <2>
8+
9+
10+
# RT = TypeVar('RT', bound=Repeatable) # <3>
11+
12+
defdouble[RT:Repeatable](x:RT)->RT:# <4>
13+
returnx*2

‎double/double_protocol_wrong.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22

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

5+
56
classRepeatable(Protocol):
67
def__mul__(self:T,repeat_count:int)->T: ...# <2>
78

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

‎double/double_sequence.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
fromcollectionsimportabc
1+
fromcollections.abcimportSequence
22
fromtypingimportTypeVar
33

44
T=TypeVar('T')
55

6-
defdouble(x:abc.Sequence[T])->Sequence[T]:
6+
defdouble(x:Sequence[T])->Sequence[T]:
77
returnx*2

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp