0001 # Augmented assignment test. 0002 0003 x = 2 0004 x += 1 0005 x *= 2 0006 x **= 2 0007 x -= 8 0008 x //= 2 0009 x //= 1 0010 x %= 12 0011 x &= 2 0012 x |= 5 0013 x ^= 1 0014 0015 print x 0016 0017 x = [2] 0018 x[0] += 1 0019 x[0] *= 2 0020 x[0] **= 2 0021 x[0] -= 8 0022 x[0] //= 2 0023 x[0] //= 2 0024 x[0] %= 12 0025 x[0] &= 2 0026 x[0] |= 5 0027 x[0] ^= 1 0028 0029 print x 0030 0031 x = {0: 2} 0032 x[0] += 1 0033 x[0] *= 2 0034 x[0] **= 2 0035 x[0] -= 8 0036 x[0] //= 2 0037 x[0] //= 1 0038 x[0] %= 12 0039 x[0] &= 2 0040 x[0] |= 5 0041 x[0] ^= 1 0042 0043 print x[0] 0044 0045 x = [1,2] 0046 x += [3,4] 0047 x *= 2 0048 0049 print x 0050 0051 x = [1, 2, 3] 0052 y = x 0053 x[1:2] *= 2 0054 y[1:2] += [1] 0055 0056 print x 0057 print x is y 0058 0059 class aug_test: 0060 def __init__(self, value): 0061 self.val = value 0062 def __radd__(self, val): 0063 return self.val + val 0064 def __add__(self, val): 0065 return aug_test(self.val + val) 0066 0067 0068 class aug_test2(aug_test): 0069 def __iadd__(self, val): 0070 self.val = self.val + val 0071 return self 0072 0073 class aug_test3(aug_test): 0074 def __iadd__(self, val): 0075 return aug_test3(self.val + val) 0076 0077 x = aug_test(1) 0078 y = x 0079 x += 10 0080 0081 print isinstance(x, aug_test) 0082 print y is not x 0083 print x.val 0084 0085 x = aug_test2(2) 0086 y = x 0087 x += 10 0088 0089 print y is x 0090 print x.val 0091 0092 x = aug_test3(3) 0093 y = x 0094 x += 10 0095 0096 print isinstance(x, aug_test3) 0097 print y is not x 0098 print x.val 0099 0100 class testall: 0101 0102 def __add__(self, val): 0103 print "__add__ called" 0104 def __radd__(self, val): 0105 print "__radd__ called" 0106 def __iadd__(self, val): 0107 print "__iadd__ called" 0108 return self 0109 0110 def __sub__(self, val): 0111 print "__sub__ called" 0112 def __rsub__(self, val): 0113 print "__rsub__ called" 0114 def __isub__(self, val): 0115 print "__isub__ called" 0116 return self 0117 0118 def __mul__(self, val): 0119 print "__mul__ called" 0120 def __rmul__(self, val): 0121 print "__rmul__ called" 0122 def __imul__(self, val): 0123 print "__imul__ called" 0124 return self 0125 0126 def __div__(self, val): 0127 print "__div__ called" 0128 def __rdiv__(self, val): 0129 print "__rdiv__ called" 0130 def __idiv__(self, val): 0131 print "__idiv__ called" 0132 return self 0133 0134 def __floordiv__(self, val): 0135 print "__floordiv__ called" 0136 return self 0137 def __ifloordiv__(self, val): 0138 print "__ifloordiv__ called" 0139 return self 0140 def __rfloordiv__(self, val): 0141 print "__rfloordiv__ called" 0142 return self 0143 0144 def __truediv__(self, val): 0145 print "__truediv__ called" 0146 return self 0147 def __itruediv__(self, val): 0148 print "__itruediv__ called" 0149 return self 0150 0151 def __mod__(self, val): 0152 print "__mod__ called" 0153 def __rmod__(self, val): 0154 print "__rmod__ called" 0155 def __imod__(self, val): 0156 print "__imod__ called" 0157 return self 0158 0159 def __pow__(self, val): 0160 print "__pow__ called" 0161 def __rpow__(self, val): 0162 print "__rpow__ called" 0163 def __ipow__(self, val): 0164 print "__ipow__ called" 0165 return self 0166 0167 def __or__(self, val): 0168 print "__or__ called" 0169 def __ror__(self, val): 0170 print "__ror__ called" 0171 def __ior__(self, val): 0172 print "__ior__ called" 0173 return self 0174 0175 def __and__(self, val): 0176 print "__and__ called" 0177 def __rand__(self, val): 0178 print "__rand__ called" 0179 def __iand__(self, val): 0180 print "__iand__ called" 0181 return self 0182 0183 def __xor__(self, val): 0184 print "__xor__ called" 0185 def __rxor__(self, val): 0186 print "__rxor__ called" 0187 def __ixor__(self, val): 0188 print "__ixor__ called" 0189 return self 0190 0191 def __rshift__(self, val): 0192 print "__rshift__ called" 0193 def __rrshift__(self, val): 0194 print "__rrshift__ called" 0195 def __irshift__(self, val): 0196 print "__irshift__ called" 0197 return self 0198 0199 def __lshift__(self, val): 0200 print "__lshift__ called" 0201 def __rlshift__(self, val): 0202 print "__rlshift__ called" 0203 def __ilshift__(self, val): 0204 print "__ilshift__ called" 0205 return self 0206 0207 x = testall() 0208 x + 1 0209 1 + x 0210 x += 1 0211 0212 x - 1 0213 1 - x 0214 x -= 1 0215 0216 x * 1 0217 1 * x 0218 x *= 1 0219 0220 if 1/2 == 0: 0221 x / 1 0222 1 / x 0223 x /= 1 0224 else: 0225 # True division is in effect, so "/" doesn't map to __div__ etc; 0226 # but the canned expected-output file requires that those get called. 0227 x.__div__(1) 0228 x.__rdiv__(1) 0229 x.__idiv__(1) 0230 0231 x // 1 0232 1 // x 0233 x //= 1 0234 0235 x % 1 0236 1 % x 0237 x %= 1 0238 0239 x ** 1 0240 1 ** x 0241 x **= 1 0242 0243 x | 1 0244 1 | x 0245 x |= 1 0246 0247 x & 1 0248 1 & x 0249 x &= 1 0250 0251 x ^ 1 0252 1 ^ x 0253 x ^= 1 0254 0255 x >> 1 0256 1 >> x 0257 x >>= 1 0258 0259 x << 1 0260 1 << x 0261 x <<= 1 0262
Generated by PyXR 0.9.4