Skip to content

Commit

Permalink
refactored __mul__ by implementing static method 'isSequence'
Browse files Browse the repository at this point in the history
  • Loading branch information
svmundada committed Feb 28, 2018
1 parent 2a6fbc1 commit 404426a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
11 changes: 11 additions & 0 deletions python/common/org/python/types/Object.java
Original file line number Diff line number Diff line change
Expand Up @@ -1122,4 +1122,15 @@ private static org.python.Object invokeComparison(org.python.Object x, org.pytho
args[0] = y;
return (org.python.Object) ((org.python.types.Method) comparator).invoke(args, null);
}

public static boolean isSequence(org.python.Object other) {
if (other instanceof org.python.types.ByteArray || other instanceof org.python.types.Bytes ||
other instanceof org.python.types.List || other instanceof org.python.types.Str ||
other instanceof org.python.types.Tuple) {

return true;
}
return false;
}

}
13 changes: 7 additions & 6 deletions python/common/org/python/types/Slice.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,17 @@ public void __delitem__(org.python.Object index) {
throw new org.python.exceptions.TypeError("'slice' object does not support item deletion");
}

// @org.python.Method(
// __doc__ = "Return true if "
// )


@org.python.Method(
__doc__ = "",
args = {"other"}
)
public org.python.Object __mul__(org.python.Object other) {
if (other instanceof org.python.types.ByteArray || other instanceof org.python.types.Bytes ||
other instanceof org.python.types.List || other instanceof org.python.types.Str ||
other instanceof org.python.types.Tuple) {
if (org.python.types.Object.isSequence(other)) {
throw new org.python.exceptions.TypeError("can't multiply sequence by non-int of type 'slice'");
} else {
return super.__mul__(other);
Expand All @@ -284,9 +287,7 @@ public org.python.Object __mul__(org.python.Object other) {
args = {"other"}
)
public org.python.Object __imul__(org.python.Object other) {
if (other instanceof org.python.types.ByteArray || other instanceof org.python.types.Bytes ||
other instanceof org.python.types.List || other instanceof org.python.types.Str ||
other instanceof org.python.types.Tuple) {
if (org.python.types.Object.isSequence(other)) {
throw new org.python.exceptions.TypeError("can't multiply sequence by non-int of type 'slice'");
} else {
return super.__imul__(other);
Expand Down

0 comments on commit 404426a

Please sign in to comment.