Lichen

Annotated tests/identity.py

716:1f9bb1de08f5
2017-03-12 Paul Boddie Merged changes from the default branch. return-value-definition
paul@231 1
print isinstance("string", string)  # True
paul@231 2
print isinstance("string", int)     # False
paul@231 3
print isinstance(123, int)          # True
paul@231 4
print isinstance(123, string)       # False
paul@231 5
print
paul@231 6
paul@231 7
class A:
paul@231 8
    pass
paul@231 9
paul@231 10
class B(A):
paul@231 11
    pass
paul@231 12
paul@231 13
class C(B):
paul@231 14
    pass
paul@231 15
paul@231 16
a = A()
paul@231 17
b = B()
paul@231 18
c = C()
paul@231 19
paul@231 20
print isinstance(a, A)              # True
paul@231 21
print isinstance(b, B)              # True
paul@231 22
print isinstance(c, C)              # True
paul@231 23
print
paul@231 24
print isinstance(a, a)              # False
paul@231 25
print isinstance(b, b)              # False
paul@231 26
print isinstance(c, c)              # False
paul@231 27
print
paul@231 28
print isinstance(A, a)              # False
paul@231 29
print isinstance(B, b)              # False
paul@231 30
print isinstance(C, c)              # False
paul@231 31
print
paul@231 32
print isinstance(a, B)              # False
paul@231 33
print isinstance(b, C)              # False
paul@231 34
print isinstance(c, A)              # True
paul@231 35
print
paul@231 36
print isinstance(a, C)              # False
paul@231 37
print isinstance(b, A)              # True
paul@231 38
print isinstance(c, B)              # True
paul@231 39
print
paul@231 40
print issubclass(A, A)              # True
paul@231 41
print issubclass(B, B)              # True
paul@231 42
print issubclass(C, C)              # True
paul@231 43
print
paul@231 44
print issubclass(a, a)              # False
paul@231 45
print issubclass(b, b)              # False
paul@231 46
print issubclass(c, c)              # False
paul@231 47
print
paul@231 48
print issubclass(a, A)              # False
paul@231 49
print issubclass(b, B)              # False
paul@231 50
print issubclass(c, C)              # False
paul@231 51
print
paul@231 52
print issubclass(A, B)              # False
paul@231 53
print issubclass(B, C)              # False
paul@231 54
print issubclass(C, A)              # True
paul@231 55
print
paul@231 56
print issubclass(A, C)              # False
paul@231 57
print issubclass(B, A)              # True
paul@231 58
print issubclass(C, B)              # True