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

Commitcf905f0

Browse files
committed
mymax: step 03
1 parentd09c627 commitcf905f0

File tree

1 file changed

+41
-0
lines changed
  • less_than/max_steps/03-two_numbers-TypeVar

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
###################################### intentional type errors
16+
17+
fromfractionsimportFraction
18+
19+
deferror_args_fraction()->None:
20+
a,b=Fraction(5,8),Fraction(7,12)
21+
expected=a
22+
result=my.max(a,b)
23+
assertresult==expected
24+
print((a,b),'->',result)
25+
print(result.numerator,result.denominator,sep='/')
26+
ifTYPE_CHECKING:
27+
reveal_type(a)
28+
reveal_type(b)
29+
reveal_type(result)
30+
31+
32+
33+
defmain():
34+
importsys
35+
forname,valinglobals().items():
36+
ifname.startswith('demo')orname.startswith('error'):
37+
print('_'*20,name)
38+
val()
39+
40+
if__name__=='__main__':
41+
main()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp