|
| 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() |