| | 1 | # The patch in #561 changes code generation for most special methods |
| | 2 | # to remove the Cython-generated wrapper and let PyType_Ready() |
| | 3 | # generate its own wrapper. (This wrapper would be used, for instance, |
| | 4 | # when using the special method as a bound method.) |
| | 5 | |
| | 6 | # To test this, we go through and verify that each affected special |
| | 7 | # method works as a bound method. |
| | 8 | |
| | 9 | __doc__ = u""" |
| | 10 | >>> vs0 = VerySpecial(0) |
| | 11 | VS __init__ 0 |
| | 12 | >>> vs1 = VerySpecial(1) |
| | 13 | VS __init__ 1 |
| | 14 | >>> vs0_add = vs0.__add__ |
| | 15 | >>> vs0_add(vs1) |
| | 16 | VS __add__ 0 1 |
| | 17 | >>> vs0_sub = vs0.__sub__ |
| | 18 | >>> vs0_sub(vs1) |
| | 19 | VS __sub__ 0 1 |
| | 20 | >>> vs0_mul = vs0.__mul__ |
| | 21 | >>> vs0_mul(vs1) |
| | 22 | VS __mul__ 0 1 |
| | 23 | >>> vs0_div = vs0.__div__ |
| | 24 | >>> vs0_div(vs1) |
| | 25 | VS __div__ 0 1 |
| | 26 | >>> vs0_mod = vs0.__mod__ |
| | 27 | >>> vs0_mod(vs1) |
| | 28 | VS __mod__ 0 1 |
| | 29 | >>> vs0_divmod = vs0.__divmod__ |
| | 30 | >>> vs0_divmod(vs1) |
| | 31 | VS __divmod__ 0 1 |
| | 32 | >>> vs0_pow = vs0.__pow__ |
| | 33 | >>> vs0_pow(vs1) |
| | 34 | VS __pow__ pow(0, 1, None) |
| | 35 | >>> vs0_pow(vs1, 13) |
| | 36 | VS __pow__ pow(0, 1, 13) |
| | 37 | >>> vs0_neg = vs0.__neg__ |
| | 38 | >>> vs0_neg() |
| | 39 | VS __neg__ 0 |
| | 40 | >>> vs0_pos = vs0.__pos__ |
| | 41 | >>> vs0_pos() |
| | 42 | VS __pos__ 0 |
| | 43 | >>> vs0_abs = vs0.__abs__ |
| | 44 | >>> vs0_abs() |
| | 45 | VS __abs__ 0 |
| | 46 | >>> vs0_nonzero = vs0.__nonzero__ |
| | 47 | >>> vs0_nonzero() |
| | 48 | VS __nonzero__ 0 |
| | 49 | False |
| | 50 | >>> vs0_invert = vs0.__invert__ |
| | 51 | >>> vs0_invert() |
| | 52 | VS __invert__ 0 |
| | 53 | >>> vs0_lshift = vs0.__lshift__ |
| | 54 | >>> vs0_lshift(vs1) |
| | 55 | VS __lshift__ 0 << 1 |
| | 56 | >>> vs0_rshift = vs0.__rshift__ |
| | 57 | >>> vs0_rshift(vs1) |
| | 58 | VS __rshift__ 0 >> 1 |
| | 59 | >>> vs0_and = vs0.__and__ |
| | 60 | >>> vs0_and(vs1) |
| | 61 | VS __and__ 0 & 1 |
| | 62 | >>> vs0_xor = vs0.__xor__ |
| | 63 | >>> vs0_xor(vs1) |
| | 64 | VS __xor__ 0 ^ 1 |
| | 65 | >>> vs0_or = vs0.__or__ |
| | 66 | >>> vs0_or(vs1) |
| | 67 | VS __or__ 0 | 1 |
| | 68 | >>> vs0_int = vs0.__int__ |
| | 69 | >>> vs0_int() |
| | 70 | VS __int__ 0 |
| | 71 | >>> vs0_long = vs0.__long__ |
| | 72 | >>> vs0_long() |
| | 73 | VS __long__ 0 |
| | 74 | >>> vs0_float = vs0.__float__ |
| | 75 | >>> vs0_float() |
| | 76 | VS __float__ 0 |
| | 77 | >>> vs0_oct = vs0.__oct__ |
| | 78 | >>> vs0_oct() |
| | 79 | VS __oct__ 0 |
| | 80 | >>> vs0_hex = vs0.__hex__ |
| | 81 | >>> vs0_hex() |
| | 82 | VS __hex__ 0 |
| | 83 | >>> vs0_iadd = vs0.__iadd__ |
| | 84 | >>> vs0_iadd(vs1) |
| | 85 | VS __iadd__ 0 += 1 |
| | 86 | >>> vs0_isub = vs0.__isub__ |
| | 87 | >>> vs0_isub(vs1) |
| | 88 | VS __isub__ 0 -= 1 |
| | 89 | >>> vs0_imul = vs0.__imul__ |
| | 90 | >>> vs0_imul(vs1) |
| | 91 | VS __imul__ 0 *= 1 |
| | 92 | >>> vs0_idiv = vs0.__idiv__ |
| | 93 | >>> vs0_idiv(vs1) |
| | 94 | VS __idiv__ 0 /= 1 |
| | 95 | >>> vs0_imod = vs0.__imod__ |
| | 96 | >>> vs0_imod(vs1) |
| | 97 | VS __imod__ 0 %= 1 |
| | 98 | >>> vs0_ipow = vs0.__ipow__ |
| | 99 | >>> vs0_ipow(vs1) |
| | 100 | VS __ipow__ 0 1 |
| | 101 | >>> vs0_ilshift = vs0.__ilshift__ |
| | 102 | >>> vs0_ilshift(vs1) |
| | 103 | VS __ilshift__ 0 <<= 1 |
| | 104 | >>> vs0_irshift = vs0.__irshift__ |
| | 105 | >>> vs0_irshift(vs1) |
| | 106 | VS __irshift__ 0 >>= 1 |
| | 107 | >>> vs0_iand = vs0.__iand__ |
| | 108 | >>> vs0_iand(vs1) |
| | 109 | VS __iand__ 0 &= 1 |
| | 110 | >>> vs0_ixor = vs0.__ixor__ |
| | 111 | >>> vs0_ixor(vs1) |
| | 112 | VS __ixor__ 0 ^= 1 |
| | 113 | >>> vs0_ior = vs0.__ior__ |
| | 114 | >>> vs0_ior(vs1) |
| | 115 | VS __ior__ 0 |= 1 |
| | 116 | >>> vs0_floordiv = vs0.__floordiv__ |
| | 117 | >>> vs0_floordiv(vs1) |
| | 118 | VS __floordiv__ 0 / 1 |
| | 119 | >>> vs0_truediv = vs0.__truediv__ |
| | 120 | >>> vs0_truediv(vs1) |
| | 121 | VS __truediv__ 0 / 1 |
| | 122 | >>> vs0_ifloordiv = vs0.__ifloordiv__ |
| | 123 | >>> vs0_ifloordiv(vs1) |
| | 124 | VS __ifloordiv__ 0 /= 1 |
| | 125 | >>> vs0_itruediv = vs0.__itruediv__ |
| | 126 | >>> vs0_itruediv(vs1) |
| | 127 | VS __itruediv__ 0 /= 1 |
| | 128 | >>> # If you define an arithmetic method, you get wrapper objects for |
| | 129 | >>> # the reversed version as well. (This behavior is unchanged by #561.) |
| | 130 | >>> vs0_radd = vs0.__radd__ |
| | 131 | >>> vs0_radd(vs1) |
| | 132 | VS __add__ 1 0 |
| | 133 | >>> vs0_rsub = vs0.__rsub__ |
| | 134 | >>> vs0_rsub(vs1) |
| | 135 | VS __sub__ 1 0 |
| | 136 | >>> vs0_rmul = vs0.__rmul__ |
| | 137 | >>> vs0_rmul(vs1) |
| | 138 | VS __mul__ 1 0 |
| | 139 | >>> vs0_rdiv = vs0.__rdiv__ |
| | 140 | >>> vs0_rdiv(vs1) |
| | 141 | VS __div__ 1 0 |
| | 142 | >>> vs0_rmod = vs0.__rmod__ |
| | 143 | >>> vs0_rmod(vs1) |
| | 144 | VS __mod__ 1 0 |
| | 145 | >>> vs0_rdivmod = vs0.__rdivmod__ |
| | 146 | >>> vs0_rdivmod(vs1) |
| | 147 | VS __divmod__ 1 0 |
| | 148 | >>> vs0_rpow = vs0.__rpow__ |
| | 149 | >>> vs0_rpow(vs1) |
| | 150 | VS __pow__ pow(1, 0, None) |
| | 151 | >>> vs0_rlshift = vs0.__rlshift__ |
| | 152 | >>> vs0_rlshift(vs1) |
| | 153 | VS __lshift__ 1 << 0 |
| | 154 | >>> vs0_rrshift = vs0.__rrshift__ |
| | 155 | >>> vs0_rrshift(vs1) |
| | 156 | VS __rshift__ 1 >> 0 |
| | 157 | >>> vs0_rand = vs0.__rand__ |
| | 158 | >>> vs0_rand(vs1) |
| | 159 | VS __and__ 1 & 0 |
| | 160 | >>> vs0_rxor = vs0.__rxor__ |
| | 161 | >>> vs0_rxor(vs1) |
| | 162 | VS __xor__ 1 ^ 0 |
| | 163 | >>> vs0_ror = vs0.__ror__ |
| | 164 | >>> vs0_ror(vs1) |
| | 165 | VS __or__ 1 | 0 |
| | 166 | >>> vs0_rfloordiv = vs0.__rfloordiv__ |
| | 167 | >>> vs0_rfloordiv(vs1) |
| | 168 | VS __floordiv__ 1 / 0 |
| | 169 | >>> vs0_rtruediv = vs0.__rtruediv__ |
| | 170 | >>> vs0_rtruediv(vs1) |
| | 171 | VS __truediv__ 1 / 0 |
| | 172 | >>> vs0_index = vs0.__index__ |
| | 173 | >>> vs0_index() |
| | 174 | VS __index__ 0 |
| | 175 | >>> vs0_getitem = vs0.__getitem__ |
| | 176 | >>> vs0_getitem('foo') |
| | 177 | VS __getitem__ 0['foo'] |
| | 178 | >>> vs0_getslice = vs0.__getslice__ |
| | 179 | >>> vs0_getslice(13, 42) |
| | 180 | VS __getslice__ 0 13 42 |
| | 181 | >>> # If you define either setslice or delslice, you get wrapper objects |
| | 182 | >>> # for both methods. (This behavior is unchanged by #561.) |
| | 183 | >>> ss_setslice = SetSlice().__setslice__ |
| | 184 | >>> ss_setslice(13, 42, 'foo') |
| | 185 | SetSlice setslice 13 42 'foo' |
| | 186 | >>> ss_delslice = SetSlice().__delslice__ |
| | 187 | >>> ss_delslice(13, 42) |
| | 188 | Traceback (most recent call last): |
| | 189 | ... |
| | 190 | NotImplementedError: 2-element slice deletion not supported by special_methods_T561.SetSlice |
| | 191 | >>> ds_setslice = DelSlice().__setslice__ |
| | 192 | >>> ds_setslice(13, 42, 'foo') |
| | 193 | Traceback (most recent call last): |
| | 194 | ... |
| | 195 | NotImplementedError: 2-element slice assignment not supported by special_methods_T561.DelSlice |
| | 196 | >>> ds_delslice = DelSlice().__delslice__ |
| | 197 | >>> ds_delslice(13, 42) |
| | 198 | DelSlice delslice 13 42 |
| | 199 | >>> sds_setslice = SetDelSlice().__setslice__ |
| | 200 | >>> sds_setslice(13, 42, 'foo') |
| | 201 | SetDelSlice setslice 13 42 'foo' |
| | 202 | >>> sds_delslice = SetDelSlice().__delslice__ |
| | 203 | >>> sds_delslice(13, 42) |
| | 204 | SetDelSlice delslice 13 42 |
| | 205 | >>> vs0_contains = vs0.__contains__ |
| | 206 | >>> vs0_contains(vs1) |
| | 207 | VS __contains__ 0 1 |
| | 208 | False |
| | 209 | >>> vs0_len = vs0.__len__ |
| | 210 | >>> vs0_len() |
| | 211 | VS __len__ 0 |
| | 212 | 0 |
| | 213 | >>> # If you define either setitem or delitem, you get wrapper objects |
| | 214 | >>> # for both methods. (This behavior is unchanged by #561.) |
| | 215 | >>> si_setitem = SetItem().__setitem__ |
| | 216 | >>> si_setitem('foo', 'bar') |
| | 217 | SetItem setitem 'foo' 'bar' |
| | 218 | >>> si_delitem = SetItem().__delitem__ |
| | 219 | >>> si_delitem('foo') |
| | 220 | Traceback (most recent call last): |
| | 221 | ... |
| | 222 | NotImplementedError: Subscript deletion not supported by special_methods_T561.SetItem |
| | 223 | >>> di_setitem = DelItem().__setitem__ |
| | 224 | >>> di_setitem('foo', 'bar') |
| | 225 | Traceback (most recent call last): |
| | 226 | ... |
| | 227 | NotImplementedError: Subscript assignment not supported by special_methods_T561.DelItem |
| | 228 | >>> di_delitem = DelItem().__delitem__ |
| | 229 | >>> di_delitem('foo') |
| | 230 | DelItem delitem 'foo' |
| | 231 | >>> sdi_setitem = SetDelItem().__setitem__ |
| | 232 | >>> sdi_setitem('foo', 'bar') |
| | 233 | SetDelItem setitem 'foo' 'bar' |
| | 234 | >>> sdi_delitem = SetDelItem().__delitem__ |
| | 235 | >>> sdi_delitem('foo') |
| | 236 | SetDelItem delitem 'foo' |
| | 237 | >>> vs0_cmp = vs0.__cmp__ |
| | 238 | >>> vs0_cmp(vs1) |
| | 239 | VS __cmp__ 0 1 |
| | 240 | 0 |
| | 241 | >>> vs0_repr = vs0.__repr__ |
| | 242 | >>> vs0_repr() |
| | 243 | VS __repr__ 0 |
| | 244 | >>> vs0_hash = vs0.__hash__ |
| | 245 | >>> vs0_hash() |
| | 246 | VS __hash__ 0 |
| | 247 | 1000 |
| | 248 | >>> vs0_call = vs0.__call__ |
| | 249 | >>> vs0_call(vs1) |
| | 250 | VS __call__ 0(1) |
| | 251 | >>> vs0_str = vs0.__str__ |
| | 252 | >>> vs0_str() |
| | 253 | VS __str__ 0 |
| | 254 | >>> # If you define either a __getattr__ or a __getattribute__, you get |
| | 255 | >>> # only a __getattribute__ method. (Without #561, defining __getattr__ |
| | 256 | >>> # would give you both __getattr__ and __getattribute__.) |
| | 257 | >>> g00 = object.__getattribute__(GetAttr(), '__getattr__') |
| | 258 | Traceback (most recent call last): |
| | 259 | ... |
| | 260 | AttributeError: 'special_methods_T561.GetAttr' object has no attribute '__getattr__' |
| | 261 | >>> g01 = object.__getattribute__(GetAttr(), '__getattribute__') |
| | 262 | >>> g01('attr') |
| | 263 | GetAttr getattr 'attr' |
| | 264 | >>> g10 = object.__getattribute__(GetAttribute(), '__getattr__') |
| | 265 | Traceback (most recent call last): |
| | 266 | ... |
| | 267 | AttributeError: 'special_methods_T561.GetAttribute' object has no attribute '__getattr__' |
| | 268 | >>> g11 = object.__getattribute__(GetAttribute(), '__getattribute__') |
| | 269 | >>> g11('attr') |
| | 270 | GetAttribute getattribute 'attr' |
| | 271 | >>> # If you define either setattr or delattr, you get wrapper objects |
| | 272 | >>> # for both methods. (This behavior is unchanged by #561.) |
| | 273 | >>> sa_setattr = SetAttr().__setattr__ |
| | 274 | >>> sa_setattr('foo', 'bar') |
| | 275 | SetAttr setattr 'foo' 'bar' |
| | 276 | >>> sa_delattr = SetAttr().__delattr__ |
| | 277 | >>> sa_delattr('foo') |
| | 278 | Traceback (most recent call last): |
| | 279 | ... |
| | 280 | AttributeError: 'special_methods_T561.SetAttr' object has no attribute 'foo' |
| | 281 | >>> da_setattr = DelAttr().__setattr__ |
| | 282 | >>> da_setattr('foo', 'bar') |
| | 283 | Traceback (most recent call last): |
| | 284 | ... |
| | 285 | AttributeError: 'special_methods_T561.DelAttr' object has no attribute 'foo' |
| | 286 | >>> da_delattr = DelAttr().__delattr__ |
| | 287 | >>> da_delattr('foo') |
| | 288 | DelAttr delattr 'foo' |
| | 289 | >>> sda_setattr = SetDelAttr().__setattr__ |
| | 290 | >>> sda_setattr('foo', 'bar') |
| | 291 | SetDelAttr setattr 'foo' 'bar' |
| | 292 | >>> sda_delattr = SetDelAttr().__delattr__ |
| | 293 | >>> sda_delattr('foo') |
| | 294 | SetDelAttr delattr 'foo' |
| | 295 | >>> # If you define __richcmp__, you get all of __lt__, __le__, |
| | 296 | >>> # __eq__, __ne__, __gt__, __ge__ (this behavior is unchanged by #561). |
| | 297 | >>> # (you don't get a __richcmp__ method, because it doesn't have a |
| | 298 | >>> # Python signature) |
| | 299 | >>> vs0_lt = vs0.__lt__ |
| | 300 | >>> vs0_lt(vs1) |
| | 301 | VS richcmp 0 1 (kind=0) |
| | 302 | >>> vs0_le = vs0.__le__ |
| | 303 | >>> vs0_le(vs1) |
| | 304 | VS richcmp 0 1 (kind=1) |
| | 305 | >>> vs0_eq = vs0.__eq__ |
| | 306 | >>> vs0_eq(vs1) |
| | 307 | VS richcmp 0 1 (kind=2) |
| | 308 | >>> vs0_ne = vs0.__ne__ |
| | 309 | >>> vs0_ne(vs1) |
| | 310 | VS richcmp 0 1 (kind=3) |
| | 311 | >>> vs0_gt = vs0.__gt__ |
| | 312 | >>> vs0_gt(vs1) |
| | 313 | VS richcmp 0 1 (kind=4) |
| | 314 | >>> vs0_ge = vs0.__ge__ |
| | 315 | >>> vs0_ge(vs1) |
| | 316 | VS richcmp 0 1 (kind=5) |
| | 317 | >>> vs0_iter = vs0.__iter__ |
| | 318 | >>> vs0_iter() |
| | 319 | VS __iter__ 0 |
| | 320 | >>> # If you define __next__, you get both __next__ and next (this behavior |
| | 321 | >>> # is unchanged by T561) |
| | 322 | >>> vs0_next = vs0.__next__ |
| | 323 | >>> vs0_next() |
| | 324 | VS next/__next__ 0 |
| | 325 | >>> vs0_next2 = vs0.next |
| | 326 | >>> vs0_next2() |
| | 327 | VS next/__next__ 0 |
| | 328 | >>> vs0_get = vs0.__get__ |
| | 329 | >>> vs0_get('instance', 'owner') |
| | 330 | VS __get__ 0 'instance' 'owner' |
| | 331 | >>> # If you define either set or delete, you get wrapper objects |
| | 332 | >>> # for both methods. (This behavior is unchanged by #561.) |
| | 333 | >>> s_set = Set().__set__ |
| | 334 | >>> s_set('instance', 'val') |
| | 335 | Set set 'instance' 'val' |
| | 336 | >>> s_delete = Set().__delete__ |
| | 337 | >>> s_delete('instance') |
| | 338 | Traceback (most recent call last): |
| | 339 | ... |
| | 340 | NotImplementedError: __delete__ |
| | 341 | >>> d_set = Delete().__set__ |
| | 342 | >>> d_set('instance', 'val') |
| | 343 | Traceback (most recent call last): |
| | 344 | ... |
| | 345 | NotImplementedError: __set__ |
| | 346 | >>> d_delete = Delete().__delete__ |
| | 347 | >>> d_delete('instance') |
| | 348 | Delete delete 'instance' |
| | 349 | >>> sd_set = SetDelete().__set__ |
| | 350 | >>> sd_set('instance', 'val') |
| | 351 | SetDelete set 'instance' 'val' |
| | 352 | >>> sd_delete = SetDelete().__delete__ |
| | 353 | >>> sd_delete('instance') |
| | 354 | SetDelete delete 'instance' |
| | 355 | >>> vs0_init = vs0.__init__ |
| | 356 | >>> vs0_init(0) |
| | 357 | VS __init__ 0 |
| | 358 | >>> # If you define __long__, you also get a wrapper object for __int__. |
| | 359 | >>> # (This behavior is unchanged by #561.) |
| | 360 | >>> Ll = Long().__long__ |
| | 361 | >>> Ll() |
| | 362 | Long __long__ |
| | 363 | >>> Li = Long().__int__ |
| | 364 | >>> Li() |
| | 365 | Long __long__ |
| | 366 | """ |
| | 367 | |
| | 368 | cdef class VerySpecial: |
| | 369 | cdef readonly int value |
| | 370 | |
| | 371 | def __init__(self, v): |
| | 372 | self.value = v |
| | 373 | print "VS __init__ %d" % self.value |
| | 374 | |
| | 375 | def __add__(self, other): |
| | 376 | print "VS __add__ %d %d" % (self.value, other.value) |
| | 377 | |
| | 378 | def __sub__(self, other): |
| | 379 | print "VS __sub__ %d %d" % (self.value, other.value) |
| | 380 | |
| | 381 | def __mul__(self, other): |
| | 382 | print "VS __mul__ %d %d" % (self.value, other.value) |
| | 383 | |
| | 384 | def __div__(self, other): |
| | 385 | print "VS __div__ %d %d" % (self.value, other.value) |
| | 386 | |
| | 387 | def __mod__(self, other): |
| | 388 | print "VS __mod__ %d %d" % (self.value, other.value) |
| | 389 | |
| | 390 | def __divmod__(self, other): |
| | 391 | print "VS __divmod__ %d %d" % (self.value, other.value) |
| | 392 | |
| | 393 | def __pow__(self, other, mod): |
| | 394 | print "VS __pow__ pow(%d, %d, %r)" % (self.value, other.value, mod) |
| | 395 | |
| | 396 | def __lshift__(self, other): |
| | 397 | print "VS __lshift__ %d << %d" % (self.value, other.value) |
| | 398 | |
| | 399 | def __rshift__(self, other): |
| | 400 | print "VS __rshift__ %d >> %d" % (self.value, other.value) |
| | 401 | |
| | 402 | def __and__(self, other): |
| | 403 | print "VS __and__ %d & %d" % (self.value, other.value) |
| | 404 | |
| | 405 | def __xor__(self, other): |
| | 406 | print "VS __xor__ %d ^ %d" % (self.value, other.value) |
| | 407 | |
| | 408 | def __or__(self, other): |
| | 409 | print "VS __or__ %d | %d" % (self.value, other.value) |
| | 410 | |
| | 411 | def __floordiv__(self, other): |
| | 412 | print "VS __floordiv__ %d / %d" % (self.value, other.value) |
| | 413 | |
| | 414 | def __truediv__(self, other): |
| | 415 | print "VS __truediv__ %d / %d" % (self.value, other.value) |
| | 416 | |
| | 417 | def __neg__(self): |
| | 418 | print "VS __neg__ %d" % self.value |
| | 419 | |
| | 420 | def __pos__(self): |
| | 421 | print "VS __pos__ %d" % self.value |
| | 422 | |
| | 423 | def __abs__(self): |
| | 424 | print "VS __abs__ %d" % self.value |
| | 425 | |
| | 426 | def __nonzero__(self): |
| | 427 | print "VS __nonzero__ %d" % self.value |
| | 428 | |
| | 429 | def __invert__(self): |
| | 430 | print "VS __invert__ %d" % self.value |
| | 431 | |
| | 432 | def __int__(self): |
| | 433 | print "VS __int__ %d" % self.value |
| | 434 | |
| | 435 | def __long__(self): |
| | 436 | print "VS __long__ %d" % self.value |
| | 437 | |
| | 438 | def __float__(self): |
| | 439 | print "VS __float__ %d" % self.value |
| | 440 | |
| | 441 | def __oct__(self): |
| | 442 | print "VS __oct__ %d" % self.value |
| | 443 | |
| | 444 | def __hex__(self): |
| | 445 | print "VS __hex__ %d" % self.value |
| | 446 | |
| | 447 | def __iadd__(self, other): |
| | 448 | print "VS __iadd__ %d += %d" % (self.value, other.value) |
| | 449 | |
| | 450 | def __isub__(self, other): |
| | 451 | print "VS __isub__ %d -= %d" % (self.value, other.value) |
| | 452 | |
| | 453 | def __imul__(self, other): |
| | 454 | print "VS __imul__ %d *= %d" % (self.value, other.value) |
| | 455 | |
| | 456 | def __idiv__(self, other): |
| | 457 | print "VS __idiv__ %d /= %d" % (self.value, other.value) |
| | 458 | |
| | 459 | def __imod__(self, other): |
| | 460 | print "VS __imod__ %d %%= %d" % (self.value, other.value) |
| | 461 | |
| | 462 | def __ipow__(self, other, mod): |
| | 463 | # We must declare mod as an argument, but we must not touch it |
| | 464 | # or we'll get a segfault. See #562 |
| | 465 | print "VS __ipow__ %d %d" % (self.value, other.value) |
| | 466 | |
| | 467 | def __ilshift__(self, other): |
| | 468 | print "VS __ilshift__ %d <<= %d" % (self.value, other.value) |
| | 469 | |
| | 470 | def __irshift__(self, other): |
| | 471 | print "VS __irshift__ %d >>= %d" % (self.value, other.value) |
| | 472 | |
| | 473 | def __iand__(self, other): |
| | 474 | print "VS __iand__ %d &= %d" % (self.value, other.value) |
| | 475 | |
| | 476 | def __ixor__(self, other): |
| | 477 | print "VS __ixor__ %d ^= %d" % (self.value, other.value) |
| | 478 | |
| | 479 | def __ior__(self, other): |
| | 480 | print "VS __ior__ %d |= %d" % (self.value, other.value) |
| | 481 | |
| | 482 | def __ifloordiv__(self, other): |
| | 483 | print "VS __ifloordiv__ %d /= %d" % (self.value, other.value) |
| | 484 | |
| | 485 | def __itruediv__(self, other): |
| | 486 | print "VS __itruediv__ %d /= %d" % (self.value, other.value) |
| | 487 | |
| | 488 | def __index__(self): |
| | 489 | print "VS __index__ %d" % self.value |
| | 490 | |
| | 491 | def __getitem__(self, index): |
| | 492 | print "VS __getitem__ %d[%r]" % (self.value, index) |
| | 493 | |
| | 494 | def __getslice__(self, a, b): |
| | 495 | print "VS __getslice__ %d %d %d" % (self.value, a, b) |
| | 496 | |
| | 497 | def __contains__(self, other): |
| | 498 | print "VS __contains__ %d %d" % (self.value, other.value) |
| | 499 | |
| | 500 | def __len__(self): |
| | 501 | print "VS __len__ %d" % (self.value) |
| | 502 | |
| | 503 | def __cmp__(self, other): |
| | 504 | print "VS __cmp__ %d %d" % (self.value, other.value) |
| | 505 | |
| | 506 | def __repr__(self): |
| | 507 | print "VS __repr__ %d" % self.value |
| | 508 | |
| | 509 | def __hash__(self): |
| | 510 | print "VS __hash__ %d" % self.value |
| | 511 | return self.value + 1000 |
| | 512 | |
| | 513 | def __call__(self, other): |
| | 514 | print "VS __call__ %d(%d)" % (self.value, other.value) |
| | 515 | |
| | 516 | def __str__(self): |
| | 517 | print "VS __str__ %d" % self.value |
| | 518 | |
| | 519 | def __richcmp__(self, other, kind): |
| | 520 | print "VS richcmp %d %d (kind=%r)" % (self.value, other.value, kind) |
| | 521 | |
| | 522 | def __iter__(self): |
| | 523 | print "VS __iter__ %d" % self.value |
| | 524 | |
| | 525 | def __next__(self): |
| | 526 | print "VS next/__next__ %d" % self.value |
| | 527 | |
| | 528 | def __get__(self, inst, own): |
| | 529 | print "VS __get__ %d %r %r" % (self.value, inst, own) |
| | 530 | |
| | 531 | cdef class SetSlice: |
| | 532 | def __setslice__(self, a, b, value): |
| | 533 | print "SetSlice setslice %d %d %r" % (a, b, value) |
| | 534 | |
| | 535 | cdef class DelSlice: |
| | 536 | def __delslice__(self, a, b): |
| | 537 | print "DelSlice delslice %d %d" % (a, b) |
| | 538 | |
| | 539 | cdef class SetDelSlice: |
| | 540 | def __setslice__(self, a, b, value): |
| | 541 | print "SetDelSlice setslice %d %d %r" % (a, b, value) |
| | 542 | |
| | 543 | def __delslice__(self, a, b): |
| | 544 | print "SetDelSlice delslice %d %d" % (a, b) |
| | 545 | |
| | 546 | cdef class SetItem: |
| | 547 | def __setitem__(self, index, value): |
| | 548 | print "SetItem setitem %r %r" % (index, value) |
| | 549 | |
| | 550 | cdef class DelItem: |
| | 551 | def __delitem__(self, index): |
| | 552 | print "DelItem delitem %r" % index |
| | 553 | |
| | 554 | cdef class SetDelItem: |
| | 555 | def __setitem__(self, index, value): |
| | 556 | print "SetDelItem setitem %r %r" % (index, value) |
| | 557 | |
| | 558 | def __delitem__(self, index): |
| | 559 | print "SetDelItem delitem %r" % index |
| | 560 | |
| | 561 | cdef class GetAttr: |
| | 562 | def __getattr__(self, attr): |
| | 563 | print "GetAttr getattr %r" % attr |
| | 564 | |
| | 565 | cdef class GetAttribute: |
| | 566 | def __getattribute__(self, attr): |
| | 567 | print "GetAttribute getattribute %r" % attr |
| | 568 | |
| | 569 | cdef class SetAttr: |
| | 570 | def __setattr__(self, attr, val): |
| | 571 | print "SetAttr setattr %r %r" % (attr, val) |
| | 572 | |
| | 573 | cdef class DelAttr: |
| | 574 | def __delattr__(self, attr): |
| | 575 | print "DelAttr delattr %r" % attr |
| | 576 | |
| | 577 | cdef class SetDelAttr: |
| | 578 | def __setattr__(self, attr, val): |
| | 579 | print "SetDelAttr setattr %r %r" % (attr, val) |
| | 580 | |
| | 581 | def __delattr__(self, attr): |
| | 582 | print "SetDelAttr delattr %r" % attr |
| | 583 | |
| | 584 | cdef class Set: |
| | 585 | def __set__(self, inst, val): |
| | 586 | print "Set set %r %r" % (inst, val) |
| | 587 | |
| | 588 | cdef class Delete: |
| | 589 | def __delete__(self, inst): |
| | 590 | print "Delete delete %r" % inst |
| | 591 | |
| | 592 | cdef class SetDelete: |
| | 593 | def __set__(self, inst, val): |
| | 594 | print "SetDelete set %r %r" % (inst, val) |
| | 595 | |
| | 596 | def __delete__(self, inst): |
| | 597 | print "SetDelete delete %r" % inst |
| | 598 | |
| | 599 | cdef class Long: |
| | 600 | def __long__(self): |
| | 601 | print "Long __long__" |