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

Commit08c1a9a

Browse files
committed
mymax: step 03
1 parentcf905f0 commit08c1a9a

File tree

2 files changed

+74
-5
lines changed

2 files changed

+74
-5
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env python3
2+
3+
fromtypingimportTYPE_CHECKING,List,Optional
4+
5+
importmymaxasmy
6+
7+
defdemo_args_float()->None:
8+
a,b=2.5,3.5
9+
expected=b
10+
result=my.max(a,b)
11+
assertresult==expected
12+
print((a,b),'->',result)
13+
14+
15+
defdemo_args_fraction()->None:
16+
a,b=Fraction(5,8),Fraction(7,12)
17+
expected=a
18+
result=my.max(a,b)
19+
assertresult==expected
20+
print((a,b),'->',result)
21+
print(result.numerator,result.denominator,sep='/')
22+
ifTYPE_CHECKING:
23+
reveal_type(a)
24+
reveal_type(b)
25+
reveal_type(result)
26+
27+
28+
defdemo_args_fraction_float()->None:
29+
a,b=Fraction(5,8),.5
30+
expected=a
31+
result=my.max(a,b)
32+
assertresult==expected
33+
print((a,b),'->',result)
34+
print(result.numerator,result.denominator,sep='/')
35+
ifTYPE_CHECKING:
36+
reveal_type(a)
37+
reveal_type(b)
38+
reveal_type(result)
39+
40+
41+
defdemo_args_float_fraction()->None:
42+
a,b=.9,Fraction(5,8)
43+
expected=a
44+
result=my.max(a,b)
45+
assertresult==expected
46+
print((a,b),'->',result)
47+
print(result.numerator,result.denominator,sep='/')
48+
ifTYPE_CHECKING:
49+
reveal_type(a)
50+
reveal_type(b)
51+
reveal_type(result)
52+
53+
54+
###################################### intentional type errors
55+
56+
fromfractionsimportFraction
57+
58+
59+
60+
defmain():
61+
importsys
62+
forname,valinglobals().items():
63+
ifname.startswith('demo')orname.startswith('error'):
64+
print('_'*20,name)
65+
val()
66+
67+
if__name__=='__main__':
68+
main()

‎less_than/max_steps/03-two_numbers-TypeVar/fixed.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ def demo_args_float() -> None:
1212
print((a,b),'->',result)
1313

1414

15-
###################################### intentional type errors
16-
17-
fromfractionsimportFraction
18-
19-
deferror_args_fraction()->None:
15+
defdemo_args_fraction()->None:
2016
a,b=Fraction(5,8),Fraction(7,12)
2117
expected=a
2218
result=my.max(a,b)
@@ -29,6 +25,11 @@ def error_args_fraction() -> None:
2925
reveal_type(result)
3026

3127

28+
###################################### intentional type errors
29+
30+
fromfractionsimportFraction
31+
32+
3233

3334
defmain():
3435
importsys

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp