Lichen

tests/identity.py

360:209dc7a270fd
2016-12-09 Paul Boddie Added support for dynamic attribute access using getattr and hasattr, employing a special attribute on strings to hold the object table code and position for any attribute having the same name as the represented string.
     1 print isinstance("string", string)  # True     2 print isinstance("string", int)     # False     3 print isinstance(123, int)          # True     4 print isinstance(123, string)       # False     5 print     6      7 class A:     8     pass     9     10 class B(A):    11     pass    12     13 class C(B):    14     pass    15     16 a = A()    17 b = B()    18 c = C()    19     20 print isinstance(a, A)              # True    21 print isinstance(b, B)              # True    22 print isinstance(c, C)              # True    23 print    24 print isinstance(a, a)              # False    25 print isinstance(b, b)              # False    26 print isinstance(c, c)              # False    27 print    28 print isinstance(A, a)              # False    29 print isinstance(B, b)              # False    30 print isinstance(C, c)              # False    31 print    32 print isinstance(a, B)              # False    33 print isinstance(b, C)              # False    34 print isinstance(c, A)              # True    35 print    36 print isinstance(a, C)              # False    37 print isinstance(b, A)              # True    38 print isinstance(c, B)              # True    39 print    40 print issubclass(A, A)              # True    41 print issubclass(B, B)              # True    42 print issubclass(C, C)              # True    43 print    44 print issubclass(a, a)              # False    45 print issubclass(b, b)              # False    46 print issubclass(c, c)              # False    47 print    48 print issubclass(a, A)              # False    49 print issubclass(b, B)              # False    50 print issubclass(c, C)              # False    51 print    52 print issubclass(A, B)              # False    53 print issubclass(B, C)              # False    54 print issubclass(C, A)              # True    55 print    56 print issubclass(A, C)              # False    57 print issubclass(B, A)              # True    58 print issubclass(C, B)              # True