Skip to content

Commit

Permalink
feedback from ryan and chip
Browse files Browse the repository at this point in the history
  • Loading branch information
nbauernfeind committed Nov 1, 2021
1 parent 07495fb commit 81c8134
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

package io.deephaven.db.tables.lang;

import io.deephaven.util.QueryConstants;
import io.deephaven.util.type.TypeUtils;
import com.github.javaparser.ast.expr.BinaryExpr;
import org.jpy.PyObject;
Expand Down Expand Up @@ -564,7 +563,7 @@ public static void main(String args[]) {
// Special casts for PyObject to primitive
buf.append(" public static int intPyCast(Object a) {\n");
buf.append(" if (a != null && !(a instanceof PyObject)) {\n");
buf.append(" throw new IllegalArgumentException(\"provided value is not a PyObject\");\n");
buf.append(" throw new IllegalArgumentException(\"Provided value is not a PyObject\");\n");
buf.append(" }\n");
buf.append(" PyObject o = (PyObject) a;\n");
buf.append(" if (o == null || o.isNone()) {\n");
Expand All @@ -575,7 +574,7 @@ public static void main(String args[]) {

buf.append(" public static double doublePyCast(Object a) {\n");
buf.append(" if (a != null && !(a instanceof PyObject)) {\n");
buf.append(" throw new IllegalArgumentException(\"provided value is not a PyObject\");\n");
buf.append(" throw new IllegalArgumentException(\"Provided value is not a PyObject\");\n");
buf.append(" }\n");
buf.append(" PyObject o = (PyObject) a;\n");
buf.append(" if (o == null || o.isNone()) {\n");
Expand All @@ -586,7 +585,7 @@ public static void main(String args[]) {

buf.append(" public static long longPyCast(Object a) {\n");
buf.append(" if (a != null && !(a instanceof PyObject)) {\n");
buf.append(" throw new IllegalArgumentException(\"provided value is not a PyObject\");\n");
buf.append(" throw new IllegalArgumentException(\"Provided value is not a PyObject\");\n");
buf.append(" }\n");
buf.append(" PyObject o = (PyObject) a;\n");
buf.append(" if (o == null || o.isNone()) {\n");
Expand All @@ -597,7 +596,7 @@ public static void main(String args[]) {

buf.append(" public static float floatPyCast(Object a) {\n");
buf.append(" if (a != null && !(a instanceof PyObject)) {\n");
buf.append(" throw new IllegalArgumentException(\"provided value is not a PyObject\");\n");
buf.append(" throw new IllegalArgumentException(\"Provided value is not a PyObject\");\n");
buf.append(" }\n");
buf.append(" PyObject o = (PyObject) a;\n");
buf.append(" if (o == null || o.isNone()) {\n");
Expand All @@ -608,7 +607,7 @@ public static void main(String args[]) {

buf.append(" public static char charPyCast(Object a) {\n");
buf.append(" if (a != null && !(a instanceof PyObject)) {\n");
buf.append(" throw new IllegalArgumentException(\"provided value is not a PyObject\");\n");
buf.append(" throw new IllegalArgumentException(\"Provided value is not a PyObject\");\n");
buf.append(" }\n");
buf.append(" PyObject o = (PyObject) a;\n");
buf.append(" if (o == null || o.isNone()) {\n");
Expand All @@ -619,7 +618,7 @@ public static void main(String args[]) {

buf.append(" public static byte bytePyCast(Object a) {\n");
buf.append(" if (a != null && !(a instanceof PyObject)) {\n");
buf.append(" throw new IllegalArgumentException(\"provided value is not a PyObject\");\n");
buf.append(" throw new IllegalArgumentException(\"Provided value is not a PyObject\");\n");
buf.append(" }\n");
buf.append(" PyObject o = (PyObject) a;\n");
buf.append(" if (o == null || o.isNone()) {\n");
Expand All @@ -630,7 +629,7 @@ public static void main(String args[]) {

buf.append(" public static short shortPyCast(Object a) {\n");
buf.append(" if (a != null && !(a instanceof PyObject)) {\n");
buf.append(" throw new IllegalArgumentException(\"provided value is not a PyObject\");\n");
buf.append(" throw new IllegalArgumentException(\"Provided value is not a PyObject\");\n");
buf.append(" }\n");
buf.append(" PyObject o = (PyObject) a;\n");
buf.append(" if (o == null || o.isNone()) {\n");
Expand All @@ -640,39 +639,36 @@ public static void main(String args[]) {
buf.append(" }\n\n");

buf.append(" public static String doStringPyCast(Object a) {\n");
buf.append(" if (a == null) {\n");
buf.append(" return null;\n");
buf.append(" }\n");
buf.append(" if (!(a instanceof PyObject)) {\n");
buf.append(" throw new IllegalArgumentException(\"provided value is not a PyObject\");\n");
buf.append(" if (a != null && !(a instanceof PyObject)) {\n");
buf.append(" throw new IllegalArgumentException(\"Provided value is not a PyObject\");\n");
buf.append(" }\n");
buf.append(" PyObject o = (PyObject) a;\n");
buf.append(" if (o.isNone()) {\n");
buf.append(" if (o == null || o.isNone()) {\n");
buf.append(" return null;\n");
buf.append(" }\n");
buf.append(" return o.getStringValue();\n");
buf.append(" }\n\n");

buf.append(" public static boolean booleanPyCast(Object a) {\n");
buf.append(" if (a == null) {\n");
buf.append(" return false;\n");
buf.append(" if (a != null && !(a instanceof PyObject)) {\n");
buf.append(" throw new IllegalArgumentException(\"Provided value is not a PyObject\");\n");
buf.append(" }\n");
buf.append(" if (!(a instanceof PyObject)) {\n");
buf.append(" throw new IllegalArgumentException(\"provided value is not a PyObject\");\n");
buf.append(" PyObject o = (PyObject) a;\n");
buf.append(" if (o == null || o.isNone()) {\n");
buf.append(" throw new NullPointerException(\"Provided value is unexpectedly null;");
buf.append(" cannot cast to boolean\");\n");
buf.append(" }\n");
buf.append(" return ((PyObject) a).getBooleanValue();\n");
buf.append(" }\n\n");

buf.append(" public static Boolean doBooleanPyCast(Object a) {\n");
buf.append(" if (a == null) {\n");
buf.append(" return null;\n");
buf.append(" }\n");
buf.append(" if (!(a instanceof PyObject)) {\n");
buf.append(" throw new IllegalArgumentException(\"provided value is not a PyObject\");\n");
buf.append(" if (a != null && !(a instanceof PyObject)) {\n");
buf.append(" throw new IllegalArgumentException(\"Provided value is not a PyObject\");\n");
buf.append(" }\n");
buf.append(" PyObject o = (PyObject) a;\n");
buf.append(" if (o.isNone()) {\n");
buf.append(" return null;\n");
buf.append(" if (o == null || o.isNone()) {\n");
// According to resident experts, the pythonic choice here is to return false.
buf.append(" return false;\n");
buf.append(" }\n");
buf.append(" return o.getBooleanValue();\n");
buf.append(" }\n\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19292,7 +19292,7 @@ public static short shortCast(Object a) {

public static int intPyCast(Object a) {
if (a != null && !(a instanceof PyObject)) {
throw new IllegalArgumentException("provided value is not a PyObject");
throw new IllegalArgumentException("Provided value is not a PyObject");
}
PyObject o = (PyObject) a;
if (o == null || o.isNone()) {
Expand All @@ -19303,7 +19303,7 @@ public static int intPyCast(Object a) {

public static double doublePyCast(Object a) {
if (a != null && !(a instanceof PyObject)) {
throw new IllegalArgumentException("provided value is not a PyObject");
throw new IllegalArgumentException("Provided value is not a PyObject");
}
PyObject o = (PyObject) a;
if (o == null || o.isNone()) {
Expand All @@ -19314,7 +19314,7 @@ public static double doublePyCast(Object a) {

public static long longPyCast(Object a) {
if (a != null && !(a instanceof PyObject)) {
throw new IllegalArgumentException("provided value is not a PyObject");
throw new IllegalArgumentException("Provided value is not a PyObject");
}
PyObject o = (PyObject) a;
if (o == null || o.isNone()) {
Expand All @@ -19325,7 +19325,7 @@ public static long longPyCast(Object a) {

public static float floatPyCast(Object a) {
if (a != null && !(a instanceof PyObject)) {
throw new IllegalArgumentException("provided value is not a PyObject");
throw new IllegalArgumentException("Provided value is not a PyObject");
}
PyObject o = (PyObject) a;
if (o == null || o.isNone()) {
Expand All @@ -19336,7 +19336,7 @@ public static float floatPyCast(Object a) {

public static char charPyCast(Object a) {
if (a != null && !(a instanceof PyObject)) {
throw new IllegalArgumentException("provided value is not a PyObject");
throw new IllegalArgumentException("Provided value is not a PyObject");
}
PyObject o = (PyObject) a;
if (o == null || o.isNone()) {
Expand All @@ -19347,7 +19347,7 @@ public static char charPyCast(Object a) {

public static byte bytePyCast(Object a) {
if (a != null && !(a instanceof PyObject)) {
throw new IllegalArgumentException("provided value is not a PyObject");
throw new IllegalArgumentException("Provided value is not a PyObject");
}
PyObject o = (PyObject) a;
if (o == null || o.isNone()) {
Expand All @@ -19358,7 +19358,7 @@ public static byte bytePyCast(Object a) {

public static short shortPyCast(Object a) {
if (a != null && !(a instanceof PyObject)) {
throw new IllegalArgumentException("provided value is not a PyObject");
throw new IllegalArgumentException("Provided value is not a PyObject");
}
PyObject o = (PyObject) a;
if (o == null || o.isNone()) {
Expand All @@ -19368,38 +19368,33 @@ public static short shortPyCast(Object a) {
}

public static String doStringPyCast(Object a) {
if (a == null) {
return null;
}
if (!(a instanceof PyObject)) {
throw new IllegalArgumentException("provided value is not a PyObject");
if (a != null && !(a instanceof PyObject)) {
throw new IllegalArgumentException("Provided value is not a PyObject");
}
PyObject o = (PyObject) a;
if (o.isNone()) {
if (o == null || o.isNone()) {
return null;
}
return o.getStringValue();
}

public static boolean booleanPyCast(Object a) {
if (a == null) {
return false;
if (a != null && !(a instanceof PyObject)) {
throw new IllegalArgumentException("Provided value is not a PyObject");
}
if (!(a instanceof PyObject)) {
throw new IllegalArgumentException("provided value is not a PyObject");
PyObject o = (PyObject) a;
if (o == null || o.isNone()) {
throw new NullPointerException("Provided value is unexpectedly null; cannot cast to boolean");
}
return ((PyObject) a).getBooleanValue();
}

public static Boolean doBooleanPyCast(Object a) {
if (a == null) {
return null;
}
if (!(a instanceof PyObject)) {
throw new IllegalArgumentException("provided value is not a PyObject");
if (a != null && !(a instanceof PyObject)) {
throw new IllegalArgumentException("Provided value is not a PyObject");
}
PyObject o = (PyObject) a;
if (o.isNone()) {
if (o == null || o.isNone()) {
return null;
}
return o.getBooleanValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ else if (fromBoxedType) {
((ret.equals(boolean.class) || ret.equals(Boolean.class) || ret.equals(String.class))
&& exprType.equals(PyObject.class));

if (toPrimitive && !ret.equals(boolean.class) && !ret.equals(exprType) || isPyUpgrade) {
if ((toPrimitive && !ret.equals(boolean.class) && !ret.equals(exprType)) || isPyUpgrade) {
// Casting to a primitive, except booleans and the identity conversion
if (!toPrimitive) {
// these methods look like `doStringPyCast` and `doBooleanPyCast`
Expand Down

0 comments on commit 81c8134

Please sign in to comment.