Skip to content
This repository has been archived by the owner on May 31, 2020. It is now read-only.

Commit

Permalink
clean up contains and not_contains
Browse files Browse the repository at this point in the history
  • Loading branch information
patiences committed Jul 27, 2018
1 parent 47312ab commit 812dbcb
Showing 1 changed file with 2 additions and 63 deletions.
65 changes: 2 additions & 63 deletions python/common/org/python/types/Object.java
Original file line number Diff line number Diff line change
Expand Up @@ -1359,28 +1359,10 @@ public static org.python.Object __ge__(org.python.Object v, org.python.Object w)
}
}

// FIXME how can __contains__/in be reflective?
public static org.python.Object __contains__(org.python.Object v, org.python.Object w) {
org.python.Object result = org.python.types.NotImplementedType.NOT_IMPLEMENTED;
boolean reflectedChecked = v.type() != w.type()
&& ((org.python.types.Bool) org.Python.isinstance(w, v.type())).value;
boolean v_builtin = isBuiltin(v);
boolean w_builtin = isBuiltin(w);

// Reflective case
if (reflectedChecked) {
if (w_builtin) {
result = w.__contains__(v);
} else {
result = invokeComparison(w, v, "__contains__");
}
org.python.Object result = null;

if (result != org.python.types.NotImplementedType.NOT_IMPLEMENTED) {
return result;
}
}

// Normal case
if (v_builtin) {
result = v.__contains__(w);
} else {
Expand All @@ -1391,19 +1373,6 @@ public static org.python.Object __contains__(org.python.Object v, org.python.Obj
return result;
}

// Now check reflection
if (!reflectedChecked) {
if (w_builtin) {
result = w.__contains__(v);
} else {
result = invokeComparison(w, v, "__contains__");
}

if (result != org.python.types.NotImplementedType.NOT_IMPLEMENTED) {
return result;
}
}

// Error case
if (org.Python.VERSION < 0x03060000) {
throw new org.python.exceptions.TypeError(String.format(
Expand All @@ -1415,25 +1384,8 @@ public static org.python.Object __contains__(org.python.Object v, org.python.Obj
}

public static org.python.Object __not_contains__(org.python.Object v, org.python.Object w) {
org.python.Object result = org.python.types.NotImplementedType.NOT_IMPLEMENTED;
boolean reflectedChecked = v.type() != w.type()
&& ((org.python.types.Bool) org.Python.isinstance(w, v.type())).value;
boolean v_builtin = isBuiltin(v);
boolean w_builtin = isBuiltin(w);

// Reflective case
if (reflectedChecked) {
if (w_builtin) {
result = w.__not_contains__(v);
} else {
result = invokeComparison(w, v, "__not_contains__");
}

if (result != org.python.types.NotImplementedType.NOT_IMPLEMENTED) {
return result;
}
}

org.python.Object result = null;
// Normal case
if (v_builtin) {
result = v.__not_contains__(w);
Expand All @@ -1445,19 +1397,6 @@ public static org.python.Object __not_contains__(org.python.Object v, org.python
return result;
}

// Now check reflection
if (!reflectedChecked) {
if (w_builtin) {
result = w.__not_contains__(v);
} else {
result = invokeComparison(w, v, "__not_contains__");
}

if (result != org.python.types.NotImplementedType.NOT_IMPLEMENTED) {
return result;
}
}

// Error case
if (org.Python.VERSION < 0x03060000) {
throw new org.python.exceptions.TypeError(String.format(
Expand Down

0 comments on commit 812dbcb

Please sign in to comment.