annotate Lib/operator.py @ 87690:66c1c9f32567 default tip

Add use_weakref option to functools.lru_cache The use_weakref option makes lru_cache create weak references to the function arguments when creating the cache key, which prevents them from staying in the memory forever even after all other references to them are gone. This is a proof of concept for http://bugs.python.org/issue19859
author Radomir Dopieralski <devel@sheep.art.pl>
date Tue, 03 Dec 2013 16:02:48 +0100
parents 7769c4d72806
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
83465
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1 #!/usr/bin/env python3
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
2 """
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
3 Operator Interface
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
4
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
5 This module exports a set of functions corresponding to the intrinsic
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
6 operators of Python. For example, operator.add(x, y) is equivalent
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
7 to the expression x+y. The function names are those used for special
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
8 methods; variants without leading and trailing '__' are also provided
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
9 for convenience.
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
10
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
11 This is the pure Python implementation of the module.
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
12 """
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
13
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
14 __all__ = ['abs', 'add', 'and_', 'attrgetter', 'concat', 'contains', 'countOf',
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
15 'delitem', 'eq', 'floordiv', 'ge', 'getitem', 'gt', 'iadd', 'iand',
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
16 'iconcat', 'ifloordiv', 'ilshift', 'imod', 'imul', 'index',
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
17 'indexOf', 'inv', 'invert', 'ior', 'ipow', 'irshift', 'is_',
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
18 'is_not', 'isub', 'itemgetter', 'itruediv', 'ixor', 'le',
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
19 'length_hint', 'lshift', 'lt', 'methodcaller', 'mod', 'mul', 'ne',
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
20 'neg', 'not_', 'or_', 'pos', 'pow', 'rshift', 'setitem', 'sub',
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
21 'truediv', 'truth', 'xor']
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
22
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
23 from builtins import abs as _abs
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
24
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
25
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
26 # Comparison Operations *******************************************************#
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
27
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
28 def lt(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
29 "Same as a < b."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
30 return a < b
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
31
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
32 def le(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
33 "Same as a <= b."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
34 return a <= b
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
35
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
36 def eq(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
37 "Same as a == b."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
38 return a == b
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
39
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
40 def ne(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
41 "Same as a != b."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
42 return a != b
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
43
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
44 def ge(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
45 "Same as a >= b."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
46 return a >= b
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
47
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
48 def gt(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
49 "Same as a > b."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
50 return a > b
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
51
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
52 # Logical Operations **********************************************************#
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
53
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
54 def not_(a):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
55 "Same as not a."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
56 return not a
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
57
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
58 def truth(a):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
59 "Return True if a is true, False otherwise."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
60 return True if a else False
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
61
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
62 def is_(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
63 "Same as a is b."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
64 return a is b
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
65
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
66 def is_not(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
67 "Same as a is not b."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
68 return a is not b
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
69
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
70 # Mathematical/Bitwise Operations *********************************************#
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
71
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
72 def abs(a):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
73 "Same as abs(a)."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
74 return _abs(a)
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
75
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
76 def add(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
77 "Same as a + b."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
78 return a + b
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
79
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
80 def and_(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
81 "Same as a & b."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
82 return a & b
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
83
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
84 def floordiv(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
85 "Same as a // b."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
86 return a // b
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
87
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
88 def index(a):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
89 "Same as a.__index__()."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
90 return a.__index__()
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
91
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
92 def inv(a):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
93 "Same as ~a."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
94 return ~a
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
95 invert = inv
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
96
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
97 def lshift(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
98 "Same as a << b."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
99 return a << b
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
100
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
101 def mod(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
102 "Same as a % b."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
103 return a % b
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
104
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
105 def mul(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
106 "Same as a * b."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
107 return a * b
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
108
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
109 def neg(a):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
110 "Same as -a."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
111 return -a
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
112
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
113 def or_(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
114 "Same as a | b."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
115 return a | b
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
116
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
117 def pos(a):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
118 "Same as +a."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
119 return +a
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
120
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
121 def pow(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
122 "Same as a ** b."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
123 return a ** b
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
124
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
125 def rshift(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
126 "Same as a >> b."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
127 return a >> b
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
128
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
129 def sub(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
130 "Same as a - b."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
131 return a - b
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
132
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
133 def truediv(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
134 "Same as a / b."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
135 return a / b
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
136
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
137 def xor(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
138 "Same as a ^ b."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
139 return a ^ b
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
140
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
141 # Sequence Operations *********************************************************#
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
142
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
143 def concat(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
144 "Same as a + b, for a and b sequences."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
145 if not hasattr(a, '__getitem__'):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
146 msg = "'%s' object can't be concatenated" % type(a).__name__
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
147 raise TypeError(msg)
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
148 return a + b
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
149
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
150 def contains(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
151 "Same as b in a (note reversed operands)."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
152 return b in a
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
153
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
154 def countOf(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
155 "Return the number of times b occurs in a."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
156 count = 0
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
157 for i in a:
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
158 if i == b:
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
159 count += 1
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
160 return count
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
161
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
162 def delitem(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
163 "Same as del a[b]."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
164 del a[b]
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
165
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
166 def getitem(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
167 "Same as a[b]."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
168 return a[b]
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
169
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
170 def indexOf(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
171 "Return the first index of b in a."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
172 for i, j in enumerate(a):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
173 if j == b:
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
174 return i
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
175 else:
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
176 raise ValueError('sequence.index(x): x not in sequence')
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
177
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
178 def setitem(a, b, c):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
179 "Same as a[b] = c."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
180 a[b] = c
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
181
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
182 def length_hint(obj, default=0):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
183 """
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
184 Return an estimate of the number of items in obj.
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
185 This is useful for presizing containers when building from an iterable.
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
186
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
187 If the object supports len(), the result will be exact. Otherwise, it may
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
188 over- or under-estimate by an arbitrary amount. The result will be an
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
189 integer >= 0.
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
190 """
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
191 if not isinstance(default, int):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
192 msg = ("'%s' object cannot be interpreted as an integer" %
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
193 type(default).__name__)
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
194 raise TypeError(msg)
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
195
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
196 try:
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
197 return len(obj)
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
198 except TypeError:
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
199 pass
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
200
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
201 try:
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
202 hint = type(obj).__length_hint__
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
203 except AttributeError:
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
204 return default
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
205
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
206 try:
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
207 val = hint(obj)
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
208 except TypeError:
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
209 return default
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
210 if val is NotImplemented:
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
211 return default
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
212 if not isinstance(val, int):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
213 msg = ('__length_hint__ must be integer, not %s' %
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
214 type(val).__name__)
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
215 raise TypeError(msg)
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
216 if val < 0:
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
217 msg = '__length_hint__() should return >= 0'
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
218 raise ValueError(msg)
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
219 return val
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
220
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
221 # Generalized Lookup Objects **************************************************#
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
222
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
223 class attrgetter:
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
224 """
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
225 Return a callable object that fetches the given attribute(s) from its operand.
83683
c2000ce25fe8 #16523: merge with 3.3.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 83465
diff changeset
226 After f = attrgetter('name'), the call f(r) returns r.name.
c2000ce25fe8 #16523: merge with 3.3.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 83465
diff changeset
227 After g = attrgetter('name', 'date'), the call g(r) returns (r.name, r.date).
c2000ce25fe8 #16523: merge with 3.3.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 83465
diff changeset
228 After h = attrgetter('name.first', 'name.last'), the call h(r) returns
83465
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
229 (r.name.first, r.name.last).
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
230 """
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
231 def __init__(self, attr, *attrs):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
232 if not attrs:
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
233 if not isinstance(attr, str):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
234 raise TypeError('attribute name must be a string')
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
235 names = attr.split('.')
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
236 def func(obj):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
237 for name in names:
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
238 obj = getattr(obj, name)
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
239 return obj
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
240 self._call = func
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
241 else:
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
242 getters = tuple(map(attrgetter, (attr,) + attrs))
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
243 def func(obj):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
244 return tuple(getter(obj) for getter in getters)
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
245 self._call = func
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
246
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
247 def __call__(self, obj):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
248 return self._call(obj)
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
249
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
250 class itemgetter:
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
251 """
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
252 Return a callable object that fetches the given item(s) from its operand.
83683
c2000ce25fe8 #16523: merge with 3.3.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 83465
diff changeset
253 After f = itemgetter(2), the call f(r) returns r[2].
c2000ce25fe8 #16523: merge with 3.3.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 83465
diff changeset
254 After g = itemgetter(2, 5, 3), the call g(r) returns (r[2], r[5], r[3])
83465
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
255 """
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
256 def __init__(self, item, *items):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
257 if not items:
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
258 def func(obj):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
259 return obj[item]
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
260 self._call = func
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
261 else:
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
262 items = (item,) + items
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
263 def func(obj):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
264 return tuple(obj[i] for i in items)
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
265 self._call = func
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
266
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
267 def __call__(self, obj):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
268 return self._call(obj)
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
269
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
270 class methodcaller:
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
271 """
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
272 Return a callable object that calls the given method on its operand.
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
273 After f = methodcaller('name'), the call f(r) returns r.name().
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
274 After g = methodcaller('name', 'date', foo=1), the call g(r) returns
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
275 r.name('date', foo=1).
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
276 """
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
277
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
278 def __init__(*args, **kwargs):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
279 if len(args) < 2:
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
280 msg = "methodcaller needs at least one argument, the method name"
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
281 raise TypeError(msg)
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
282 self = args[0]
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
283 self._name = args[1]
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
284 self._args = args[2:]
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
285 self._kwargs = kwargs
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
286
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
287 def __call__(self, obj):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
288 return getattr(obj, self._name)(*self._args, **self._kwargs)
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
289
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
290 # In-place Operations *********************************************************#
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
291
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
292 def iadd(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
293 "Same as a += b."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
294 a += b
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
295 return a
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
296
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
297 def iand(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
298 "Same as a &= b."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
299 a &= b
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
300 return a
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
301
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
302 def iconcat(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
303 "Same as a += b, for a and b sequences."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
304 if not hasattr(a, '__getitem__'):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
305 msg = "'%s' object can't be concatenated" % type(a).__name__
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
306 raise TypeError(msg)
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
307 a += b
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
308 return a
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
309
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
310 def ifloordiv(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
311 "Same as a //= b."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
312 a //= b
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
313 return a
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
314
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
315 def ilshift(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
316 "Same as a <<= b."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
317 a <<= b
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
318 return a
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
319
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
320 def imod(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
321 "Same as a %= b."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
322 a %= b
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
323 return a
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
324
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
325 def imul(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
326 "Same as a *= b."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
327 a *= b
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
328 return a
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
329
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
330 def ior(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
331 "Same as a |= b."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
332 a |= b
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
333 return a
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
334
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
335 def ipow(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
336 "Same as a **= b."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
337 a **=b
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
338 return a
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
339
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
340 def irshift(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
341 "Same as a >>= b."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
342 a >>= b
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
343 return a
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
344
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
345 def isub(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
346 "Same as a -= b."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
347 a -= b
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
348 return a
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
349
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
350 def itruediv(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
351 "Same as a /= b."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
352 a /= b
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
353 return a
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
354
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
355 def ixor(a, b):
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
356 "Same as a ^= b."
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
357 a ^= b
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
358 return a
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
359
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
360
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
361 try:
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
362 from _operator import *
84442
7769c4d72806 Issue #18200: Back out usage of ModuleNotFoundError (8d28d44f3a9a)
Brett Cannon <brett@python.org>
parents: 84114
diff changeset
363 except ImportError:
83465
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
364 pass
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
365 else:
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
366 from _operator import __doc__
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
367
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
368 # All of these "__func__ = func" assignments have to happen after importing
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
369 # from _operator to make sure they're set to the right function
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
370 __lt__ = lt
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
371 __le__ = le
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
372 __eq__ = eq
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
373 __ne__ = ne
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
374 __ge__ = ge
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
375 __gt__ = gt
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
376 __not__ = not_
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
377 __abs__ = abs
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
378 __add__ = add
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
379 __and__ = and_
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
380 __floordiv__ = floordiv
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
381 __index__ = index
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
382 __inv__ = inv
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
383 __invert__ = invert
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
384 __lshift__ = lshift
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
385 __mod__ = mod
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
386 __mul__ = mul
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
387 __neg__ = neg
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
388 __or__ = or_
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
389 __pos__ = pos
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
390 __pow__ = pow
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
391 __rshift__ = rshift
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
392 __sub__ = sub
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
393 __truediv__ = truediv
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
394 __xor__ = xor
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
395 __concat__ = concat
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
396 __contains__ = contains
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
397 __delitem__ = delitem
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
398 __getitem__ = getitem
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
399 __setitem__ = setitem
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
400 __iadd__ = iadd
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
401 __iand__ = iand
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
402 __iconcat__ = iconcat
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
403 __ifloordiv__ = ifloordiv
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
404 __ilshift__ = ilshift
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
405 __imod__ = imod
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
406 __imul__ = imul
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
407 __ior__ = ior
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
408 __ipow__ = ipow
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
409 __irshift__ = irshift
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
410 __isub__ = isub
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
411 __itruediv__ = itruediv
97834382c6cc Issue #16694: Add a pure Python implementation of the operator module.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
412 __ixor__ = ixor