Ignore none type for pythonexception (#237)
* Making TypeName enum public * Ignoring None type object for PythonExceptions * better handling of None + test Co-authored-by: Fariz Rahman <farizrahman4u@gmail.com>master
parent
f0c684020f
commit
5c9e0bc2bb
|
@ -226,7 +226,7 @@ public class PythonExecutioner {
|
|||
|
||||
private static void throwIfExecutionFailed() throws PythonException{
|
||||
PythonObject ex = getVariable(PYTHON_EXCEPTION_KEY);
|
||||
if (ex != null && !ex.toString().isEmpty()){
|
||||
if (ex != null && !ex.isNone() && !ex.toString().isEmpty()) {
|
||||
setVariable(PYTHON_EXCEPTION_KEY, new PythonObject(""));
|
||||
throw new PythonException(ex);
|
||||
}
|
||||
|
|
|
@ -583,7 +583,9 @@ public class PythonObject {
|
|||
}
|
||||
}
|
||||
public boolean isNone() {
|
||||
return nativePythonObject == null;
|
||||
return (nativePythonObject == null)||
|
||||
(toString().equals("None") && Python.type(this).toString().equals("<class 'NoneType'>"));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -322,5 +322,16 @@ public class TestPythonExecutioner {
|
|||
Python.setMainContext();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsNone(){
|
||||
PythonObject d = Python.dict();
|
||||
PythonObject none = d.attr("get").call("x");
|
||||
Assert.assertTrue(none.isNone());
|
||||
d.set(new PythonObject("x"), new PythonObject("y"));
|
||||
PythonObject notNone = d.attr("get").call("x");
|
||||
Assert.assertFalse(notNone.isNone());
|
||||
Assert.assertEquals("y", notNone.toString());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue