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
Shams Ul Azeem 2020-02-13 03:58:39 +05:00 committed by GitHub
parent f0c684020f
commit 5c9e0bc2bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 2 deletions

View File

@ -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);
}

View File

@ -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'>"));
}
}

View File

@ -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());
}
}