[Python-Dev] Jython and bool (original) (raw)
Samuele Pedroni pedroni@inf.ethz.ch
Sun, 10 Mar 2002 21:06:20 +0100
- Previous message: [Python-Dev] Bug changes emails: SF problem?
- Next message: [Python-Dev] test_largefile.py failing on Linux
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Maybe this is insightful, namely how Jython now deals with Java methods with boolean in their signature and overloading, and the possible scenarios in case the PEP is approved.
Let's consider the following Java class:
public class Ex {
public void mint(int v) {}
public void mib(boolean b) {} public void mib(int v) {}
public mbool(boolean b) {}
boolean mtrue() { return true; } boolean mfalse() { return false; }
void pass(Object o) {} void passBool(Boolean bo) {}
}
let ex=Ex() be an instance of Ex.
*** NOW ex.mint(0) and ex.mint(1) do the obvious thing
ex.mib(0),ex.mib(1) call ex.mib(int v)
ex.mbool(0) and ex.mbool(1) invoke ex.mbool with false and true ex.mbool(non-integer-non-java.lang.Boolean) fails
ex.mtrue() returns 1 ex.mfalse() return 0
which means that ex.mib(ex.mtrue()) calls ex.mib(int v). [ to call ex.mib(boolean b) one should use ex.mib(java.lang.Boolean(value)) ]
ex.pass(0) and ex.pass(1) call ex.pass with java.lang.Integer(0) and java.lang.Integer(1) ex.passBool(0) and ex.passBool(1) call ex.pass with java.lang.Boolean.FALSE and java.lang.Boolean.TRUE
*** with True and False, bool is subclass of int A) treat True as 1, False as 0 and leave everything as above (no pain,no gain) that means for dispatching java methods int and bool are the same, possibliy ex.mtrue() returns True and ex.mfalse() returns False B) ex.pass(0) and ex.pass(1) call ex.pass with java.lang.Integer(0) and java.lang.Integer(1).
ex.passBool(0) and ex.passBool(1) call ex.pass with java.lang.Boolean.FALSE and java.lang.Boolean.TRUE
ex.pass(False) and ex.pass(True) call ex.pass with java.lang.Boolean.FALSE and java.lang.Boolean.TRUE (plus warning in the transition phase), same for ex.passBool
ex.mtrue()/ex.mfalse() return True/False
ex.mbool(non-integer-non-bool-non-java.lang.Boolean) fails ex.mbool(0) and ex.mbool(1) invoke ex.mbool with false and true ex.mbool(False) and ex.mbool(True) invoke ex.mbool with false and true
ex.mib(0),ex.mib(1) call ex.mib(int v) ex.mib(False) and ex.mib(True) call ex.mib(boolean b) issuing a warning during a transition phase [involved to issue!] [ex.mib with a java.lang.Boolean still calls ex.mib(boolean b) so no problem there]
ex.mint(0) and ex.mint(1) do the obvious thing ex.mint(False) and ex.mint(True) either fail [easy to implement] or call ex.mint with 0/1 [involved!] (?)
*** with True and False, bool disujunct from int ex.pass(0) and ex.pass(1) call ex.pass with java.lang.Integer(0) and java.lang.Integer(1)
ex.passBool(0) and ex.passBool(1) maybe should fail after long transition ?
ex.pass(False) and ex.pass(True) call ex.pass with java.lang.Boolean.FALSE and java.lang.Boolean.True (plus warning in the transition phase), same for ex.passBool
ex.mtrue()/ex.mfalse() return True/False
ex.mbool(non-bool-non-java.lang.Boolean) and ex.mbool(0) and ex.mbool(1) should fail after long transition ?
ex.mbool(False) and ex.mbool(True) invoke ex.mbool with false and true
ex.mib(0),ex.mib(1) call ex.mib(int v) ex.mib(False) and ex.mib(True) call ex.mib(boolean b) issuing a warning during a transition phase [involved to issue!] [ex.mib with a java.lang.Boolean still calls ex.mib(boolean b) so no problem there]
ex.mint(0) and ex.mint(1) do the obvious thing ex.mint(False) and ex.mint(True) should fail after transition and maybe call ex.mint with 0/1 with warning during transition phase [involved!] (?)
"maybe should fail after long transition ?" questions:
Very likely not, user will be very unhappy to have to change all their
jframe.setVisible(1) or equivalent jframe.visible = 1
So for Jython bool solves a very minor wart with a more or less affordable transition cost and increasing amounts of purity only make us guilty not to able to do something with them, for very practical reasons .
regards.
- Previous message: [Python-Dev] Bug changes emails: SF problem?
- Next message: [Python-Dev] test_largefile.py failing on Linux
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]