Lichen

Annotated tests/name_attribute.py

750:44ea0968a550
2017-03-20 Paul Boddie Added the context identity to the AttrResult string representation.
paul@326 1
import operator
paul@326 2
paul@326 3
class C:
paul@497 4
    def f(self): pass
paul@326 5
paul@499 6
def name(x):
paul@499 7
    print x.__name__
paul@499 8
    print x.__parent__.__name__
paul@499 9
    print str(x)
paul@499 10
paul@499 11
def attrname(x):
paul@499 12
    print x.f.__name__
paul@499 13
    print x.f.__parent__.__name__
paul@499 14
    print str(x.f)
paul@499 15
paul@326 16
c = C()
paul@489 17
print c.__name__                        # C
paul@499 18
print c.__parent__.__name__             # __main__
paul@499 19
print str(c)                            # <__main__.C instance>
paul@489 20
print C.__name__                        # C
paul@499 21
print C.__parent__.__name__             # __main__
paul@499 22
print str(C)                            # __main__.C
paul@499 23
print c.f.__name__                      # f
paul@499 24
print c.f.__parent__.__name__           # C
paul@499 25
print str(c.f)                          # __main__.C.f
paul@499 26
print C.f.__name__                      # f
paul@499 27
print C.f.__parent__.__name__           # C
paul@499 28
print str(C.f)                          # __main__.C.f
paul@499 29
paul@499 30
name(c)                                 # C
paul@499 31
                                        # __main__
paul@499 32
                                        # <__main__.C instance>
paul@499 33
name(C)                                 # C
paul@499 34
                                        # __main__
paul@499 35
                                        # __main__.C
paul@499 36
attrname(c)                             # f
paul@499 37
                                        # C
paul@499 38
                                        # __main__.C.f
paul@499 39
attrname(C)                             # f
paul@499 40
                                        # C
paul@499 41
                                        # __main__.C.f
paul@499 42
name(c.f)                               # f
paul@499 43
                                        # C
paul@499 44
                                        # __main__.C.f
paul@499 45
name(C.f)                               # f
paul@499 46
                                        # C
paul@499 47
                                        # __main__.C.f
paul@326 48
paul@489 49
# If it were defined, operator.__name__ would be module.
paul@326 50
paul@499 51
print operator.__name__                 # operator
paul@326 52
paul@489 53
# If it were defined, operator.add.__name__ would be function.
paul@326 54
paul@499 55
print operator.add.__name__             # add
paul@499 56
print operator.add.__parent__.__name__  # operator.binary