Skip to content

Commit

Permalink
Factor out __isub__.
Browse files Browse the repository at this point in the history
All of the tests for subtraction now pass.
  • Loading branch information
tbeadle committed Aug 31, 2017
1 parent edb0966 commit c49d8f2
Show file tree
Hide file tree
Showing 9 changed files with 7 additions and 62 deletions.
18 changes: 0 additions & 18 deletions python/common/org/python/types/Bool.java
Original file line number Diff line number Diff line change
Expand Up @@ -554,24 +554,6 @@ public org.python.Object __ror__(org.python.Object other) {

}

@org.python.Method(
__doc__ = "",
args = {"other"}
)
public org.python.Object __isub__(org.python.Object other) {
int this_val = (((org.python.types.Bool) this).value ? 1 : 0);
if (other instanceof org.python.types.Bool) {
this_val -= (((org.python.types.Bool) other).value ? 1 : 0);
return new org.python.types.Int(this_val);
} else if (other instanceof org.python.types.Int) {
this_val -= ((org.python.types.Int) other).value;
return new org.python.types.Int(this_val);
} else if (other instanceof org.python.types.Float) {
return new org.python.types.Float(this_val - ((org.python.types.Float) other).value);
}
throw new org.python.exceptions.TypeError("unsupported operand type(s) for -=: 'bool' and '" + other.typeName() + "'");
}

@org.python.Method(
__doc__ = "",
args = {"other"}
Expand Down
5 changes: 5 additions & 0 deletions python/common/org/python/types/Float.java
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ public org.python.Object __sub__(org.python.Object other) {
return new org.python.types.Float(this.value - 1.0);
}
return new org.python.types.Float(this.value);
} else if (other instanceof org.python.types.Complex) {
return new org.python.types.Complex(
new org.python.types.Float(this.value - ((org.python.types.Complex)other).real.value),
new org.python.types.Float(-((org.python.types.Complex)other).imag.value)
);
}
throw new org.python.exceptions.TypeError("unsupported operand type(s) for -: 'float' and '" + other.typeName() + "'");
}
Expand Down
22 changes: 0 additions & 22 deletions python/common/org/python/types/Int.java
Original file line number Diff line number Diff line change
Expand Up @@ -751,28 +751,6 @@ public org.python.Object __ilshift__(org.python.Object other) {
throw new org.python.exceptions.TypeError("unsupported operand type(s) for <<=: 'int' and '" + other.typeName() + "'");
}

@org.python.Method(
__doc__ = "",
args = {"other"}
)
public org.python.Object __isub__(org.python.Object other) {
if (other instanceof org.python.types.Int) {
this.value -= ((org.python.types.Int) other).value;
return new org.python.types.Int(this.value);
} else if (other instanceof org.python.types.Float) {
double this_val = this.value;
this_val -= ((org.python.types.Float) other).value;
return new org.python.types.Float(this_val);
} else if (other instanceof org.python.types.Bool) {
this.value -= (((org.python.types.Bool) other).value ? 1 : 0);
return new org.python.types.Int(this.value);
} else if (other instanceof org.python.types.Complex) {
org.python.types.Complex other_cmplx_obj = (org.python.types.Complex) other;
return new org.python.types.Complex(this.value - other_cmplx_obj.real.value, -(other_cmplx_obj.imag.value));
}
throw new org.python.exceptions.TypeError("unsupported operand type(s) for -=: 'int' and '" + other.typeName() + "'");
}

@org.python.Method(
__doc__ = "",
args = {"other"}
Expand Down
3 changes: 1 addition & 2 deletions python/common/org/python/types/Object.java
Original file line number Diff line number Diff line change
Expand Up @@ -801,8 +801,7 @@ public org.python.Object __iadd__(org.python.Object other) {
)
public org.python.Object __isub__(org.python.Object other) {
try {
this.setValue(this.__sub__(other));
return this;
return this.__sub__(other);
} catch (org.python.exceptions.TypeError e) {
throw new org.python.exceptions.TypeError("unsupported operand type(s) for -=: '" + this.typeName() + "' and '" + other.typeName() + "'");
}
Expand Down
7 changes: 0 additions & 7 deletions python/common/org/python/types/Set.java
Original file line number Diff line number Diff line change
Expand Up @@ -378,13 +378,6 @@ public org.python.Object __or__(org.python.Object other) {
// throw new org.python.exceptions.NotImplementedError("__ror__() has not been implemented");
// }

// @org.python.Method(
// __doc__ = ""
// )
// public void __isub__(org.python.Object other) {
// throw new org.python.exceptions.NotImplementedError("__isub__() has not been implemented");
// }

// @org.python.Method(
// __doc__ = ""
// )
Expand Down
3 changes: 1 addition & 2 deletions python/common/org/python/types/Super.java
Original file line number Diff line number Diff line change
Expand Up @@ -701,8 +701,7 @@ public org.python.Object __iadd__(org.python.Object other) {
)
public org.python.Object __isub__(org.python.Object other) {
try {
this.setValue(this.__sub__(other));
return this;
return this.__sub__(other);
} catch (org.python.exceptions.TypeError e) {
throw new org.python.exceptions.TypeError("unsupported operand type(s) for -=: 'super()' and '" + other.typeName() + "'");
}
Expand Down
2 changes: 0 additions & 2 deletions tests/datatypes/test_bool.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ class InplaceBoolOperationTests(InplaceOperationTestCase, TranspileTestCase):
'test_power_float',
'test_power_int',

'test_subtract_complex',

'test_true_divide_bool',
'test_true_divide_complex',
'test_true_divide_float',
Expand Down
5 changes: 0 additions & 5 deletions tests/datatypes/test_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,6 @@ class InplaceComplexOperationTests(InplaceOperationTestCase, TranspileTestCase):
'test_subscr_str',
'test_subscr_tuple',

'test_subtract_bool',
'test_subtract_complex',
'test_subtract_float',
'test_subtract_int',

'test_true_divide_bool',
'test_true_divide_complex',
'test_true_divide_float',
Expand Down
4 changes: 0 additions & 4 deletions tests/datatypes/test_float.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,6 @@ class BinaryFloatOperationTests(BinaryOperationTestCase, TranspileTestCase):
'test_subscr_str',
'test_subscr_tuple',

'test_subtract_complex',

'test_true_divide_complex',
]

Expand All @@ -162,7 +160,5 @@ class InplaceFloatOperationTests(InplaceOperationTestCase, TranspileTestCase):
'test_power_complex',
'test_power_float',

'test_subtract_complex',

'test_true_divide_complex',
]

0 comments on commit c49d8f2

Please sign in to comment.