Skip to content

Commit d15618c

Browse files
committed
Restoring behaviour of __div__ and consorts
1 parent efb908f commit d15618c

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

future/types/newint.py

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -127,28 +127,31 @@ def __rmul__(self, other):
127127
return other * long(self)
128128
return value
129129

130-
#def __div__(self, other):
131-
#value = long(self) / other
132-
#if isint(value):
133-
#return newint(value)
134-
#else:
135-
#return value
136-
137-
#def __rdiv__(self, other):
138-
#value = other / long(self)
139-
#if isint(value):
140-
#return newint(value)
141-
#else:
142-
#return value
143-
144-
#def __idiv__(self, other):
145-
## long has no __idiv__ method. Use __itruediv__ and cast back to
146-
## newint:
147-
#value = self.__itruediv__(other)
148-
#if isinstance(other, (int, long)):
149-
#return newint(value)
150-
#else:
151-
#return value
130+
def __div__(self, other):
131+
# We override this rather than e.g. relying on object.__div__ or
132+
# long.__div__ because we want to wrap the value in a newint()
133+
# call if other is another int
134+
value = long(self) / other
135+
if isinstance(other, (int, long)):
136+
return newint(value)
137+
else:
138+
return value
139+
140+
def __rdiv__(self, other):
141+
value = other / long(self)
142+
if isinstance(other, (int, long)):
143+
return newint(value)
144+
else:
145+
return value
146+
147+
def __idiv__(self, other):
148+
# long has no __idiv__ method. Use __itruediv__ and cast back to
149+
# newint:
150+
value = self.__itruediv__(other)
151+
if isinstance(other, (int, long)):
152+
return newint(value)
153+
else:
154+
return value
152155

153156
def __truediv__(self, other):
154157
value = super(newint, self).__truediv__(other)

0 commit comments

Comments
 (0)