UniSize/Ushuaya | UniSize/s02190253 | ||||
---|---|---|---|---|---|
n | 1 | class Dsc: | n | 1 | class Ctr: |
2 | |||||
3 | def __get__(self, obj, cls): | 2 | def __get__(self, obj, cls): | ||
n | 4 | #print(f"Get from {cls}:{obj}") | n | ||
5 | try: | 3 | try: | ||
6 | return len(obj) | 4 | return len(obj) | ||
7 | except BaseException: | 5 | except BaseException: | ||
8 | try: | 6 | try: | ||
9 | return abs(obj) | 7 | return abs(obj) | ||
10 | except BaseException: | 8 | except BaseException: | ||
11 | return 0 | 9 | return 0 | ||
12 | 10 | ||||
13 | 11 | ||||
14 | def sizer(cls): | 12 | def sizer(cls): | ||
n | 15 | cls.size = Dsc() | n | 13 | cls.size = Ctr() |
16 | return cls | 14 | return cls | ||
17 | 15 | ||||
t | 18 | # @sizer | t | ||
19 | # class S(str): | ||||
20 | # pass | ||||
21 | |||||
22 | # @sizer | ||||
23 | # class N(complex): | ||||
24 | # pass | ||||
25 | |||||
26 | # @sizer | ||||
27 | # class E(Exception): | ||||
28 | # pass | ||||
29 | |||||
30 | # for obj in S("QWER"), N(3+4j), E("Exceptions know no lengths!"): | ||||
31 | # print(obj, obj.size) | ||||
32 |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|