1# mode: run 2# tag: pyclass, global 3 4 5pyvar = 2 6 7class TestPyAttr(object): 8 """ 9 >>> TestPyAttr.pyvar # doctest: +ELLIPSIS 10 Traceback (most recent call last): 11 AttributeError: ...TestPyAttr...has no attribute 'pyvar' 12 >>> TestPyAttr.pyval1 13 3 14 >>> TestPyAttr.pyval2 15 2 16 """ 17 pyvar = 3 18 pyval1 = pyvar 19 del pyvar 20 pyval2 = pyvar 21 22 23import cython 24cdefvar = cython.declare(int, 10) 25 26class TestCdefAttr(object): 27 """ 28 >>> TestCdefAttr.cdefvar # doctest: +ELLIPSIS 29 Traceback (most recent call last): 30 AttributeError: ...TestCdefAttr...has no attribute 'cdefvar' 31 >>> TestCdefAttr.cdefval1 32 11 33 34 >>> #TestCdefAttr.cdefval2 35 """ 36 cdefvar = 11 37 cdefval1 = cdefvar 38 del cdefvar 39 # cdefval2 = cdefvar # FIXME: doesn't currently work ... 40 41 42class ForLoopInPyClass(object): 43 """ 44 >>> ForLoopInPyClass.i # doctest: +ELLIPSIS 45 Traceback (most recent call last): 46 AttributeError: ...ForLoopInPyClass... has no attribute ...i... 47 >>> ForLoopInPyClass.k 48 0 49 >>> ForLoopInPyClass.m 50 1 51 """ 52 for i in range(0): 53 pass 54 55 for k in range(1): 56 pass 57 58 for m in range(2): 59 pass 60 61 62def del_in_class(x): 63 """ 64 >>> del_in_class(True) 65 no error 66 >>> del_in_class(False) 67 NameError 68 """ 69 try: 70 class Test(object): 71 if x: 72 attr = 1 73 del attr 74 except NameError: 75 print("NameError") 76 else: 77 print("no error") 78