UniSize/s02190253 | UniSize/Ushuaya | ||||
---|---|---|---|---|---|
n | 1 | class Ctr: | n | 1 | class Dsc: |
2 | |||||
2 | def __get__(self, obj, cls): | 3 | def __get__(self, obj, cls): | ||
n | n | 4 | #print(f"Get from {cls}:{obj}") | ||
3 | try: | 5 | try: | ||
4 | return len(obj) | 6 | return len(obj) | ||
5 | except BaseException: | 7 | except BaseException: | ||
6 | try: | 8 | try: | ||
7 | return abs(obj) | 9 | return abs(obj) | ||
8 | except BaseException: | 10 | except BaseException: | ||
9 | return 0 | 11 | return 0 | ||
10 | 12 | ||||
11 | 13 | ||||
12 | def sizer(cls): | 14 | def sizer(cls): | ||
n | 13 | cls.size = Ctr() | n | 15 | cls.size = Dsc() |
14 | return cls | 16 | return cls | ||
15 | 17 | ||||
t | t | 18 | # @sizer | ||
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 | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|